yasirkula / UnityNativeShare

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

[Question] The posting process on Android is not completed in the app. Is that the spec? #137

Open wataru-hasegawa opened 2 years ago

wataru-hasegawa commented 2 years ago

Description First of all, I would like to thank you for creating a great library. Well, I added a function that takes a screenshot, resizes it, and then posts the image to another app.

It works fine without crashing or anything. However, when I tested it on Facebook and Twitter, the behavior was different depending on the OS as follows

In the case of Android, even if I check the post on my desktop after posting, the post does not appear for any length of time. When I launched the target app from the device where I posted, the posting process started and after waiting for a few seconds, the posting was completed. The point is that the posting process on Android is only up to the point where it is put into the queue of the target app, and it is not done until I launch the app from the same device.

Is that the spec on Android?

It probably doesn't matter, but I'll post my code in case it does.

    public IEnumerator ImageShoot(){
        yield return new WaitForEndOfFrame();

        Texture2D tex = ScreenCapture.CaptureScreenshotAsTexture();
        int width = tex.width;
        int height = width;
        int x = (tex.width - width) / 2;
        int y = (tex.height - height) / 2;
        Color[] colors = tex.GetPixels(x, y, width, height);
        tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
        tex.SetPixels(colors);
        string path = Path.Combine( Application.temporaryCachePath, "result.png");

        File.WriteAllBytes(path, tex.EncodeToPNG());
        Destroy(tex);
        new NativeShare().AddFile(path)
            .SetCallback((result, shareTarget) => AfterShare(shareTarget))
            .Share();
    }

Thanks,

yasirkula commented 2 years ago

To check whether or not this is an issue on Facebook-side, can you try sharing to Facebook from other apps installed on your device and see if some or all of them also encounter the same issue while sharing to Facebook?

wataru-hasegawa commented 2 years ago

Hi yasirkula, Thanks for the reply. The same behavior is happening on twitter as well as on Facebook. I haven't tested the other apps yet, so I'll test them just in case.

yasirkula commented 2 years ago

I meant sharing something from e.g. Twitter to Facebook, Facebook to Twitter, WhatsApp to Facebook and etc. Do they also suffer from this issue?

wataru-hasegawa commented 2 years ago

Hi @yasirkula , Sorry for the misunderstanding. Well, I tested it from Instagram to facebook and twitter on Android.

Sharing from Instagram doesn't have any problem. Thanks,

yasirkula commented 2 years ago

I see. Does running this code with true or false at Start/Awake make any difference:

using( AndroidJavaClass ajc = new AndroidJavaClass( "com.yasirkula.unity.NativeShare" ) )
    ajc.SetStatic<bool>( "alwaysUseCustomShareDialog", true );
wataru-hasegawa commented 2 years ago

I added the above code and tested it with both true/false.

I guess that code addition is probably a temporary fix, but it seems to work fine when putting true! Thanks,

wataru-hasegawa commented 2 years ago

I have added the code with "true" and continue testing, but it seems that sometimes the target app doesn't launch.

I'm not sure under what conditions the behavior differs, so I'll do some more testing. Thanks,

yasirkula commented 2 years ago

I'll take a look at it when I get the chance, thanks for confirming it.

yasirkula commented 2 years ago

Does replacing Plugins/NativeShare/Android/NativeShare.aar with the one inside this zip archive make any difference when you use/not use the code I've posted the last time?