yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
891 stars 131 forks source link

Unity NativeShare Screenshot share not working(Android) #45

Closed HarshPatel19011995 closed 4 years ago

HarshPatel19011995 commented 4 years ago

I use the Native share plugine screenshots code not working in android, I use the native share link sharing its working good but for screenshot its not working, and I new to in C#, Plz help me out, In following I wrote down my code which i made from https://github.com/yasirkula/UnityNativeShare.

public void Nativshare2() {

    StartCoroutine( TakeSSAndShare() );
    Debug.LogError ("button works");
}

private IEnumerator TakeSSAndShare()
{
    yield return new WaitForEndOfFrame();

    Texture2D ss = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
    ss.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
    ss.Apply();

    string filePath = Path.Combine( Application.temporaryCachePath, "shared img.png" );
    File.WriteAllBytes( filePath, ss.EncodeToPNG() );

    // To avoid memory leaks
    //Destroy( ss );

    new NativeShare().AddFile( filePath ).SetSubject( "Subject goes here" ).SetText( "Hello world!" ).Share();

    Debug.Log ("Share is Over");
}
yasirkula commented 4 years ago

What happens if you omit the text from the shared content, i.e.: new NativeShare().AddFile( filePath ).Share();

yasirkula commented 4 years ago

Closing the issue due to inactivity.