Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

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

Open
wataru-hasegawa opened this issue Dec 24, 2021 · 9 comments
Labels

Comments

@wataru-hasegawa
Copy link

  • Unity: 2020.3.9f1
  • Native Share for Android & iOS: 1.4.4
  • Platform: Android
  • Device: LG Electronics, L-02K
  • How did you download the plugin: Asset Store

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

  • IOS
    After posting, it appears the posting indication in my app, and after a few seconds, the posting is completed and the modal closes.

  • Android
    After posting, the modal closes immediately without the posting indication in my app.

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

  • From My App
    After posting, the modal closes immediately without the posting indication.
    I don't find the posting when I check it on the desktop.
    The posting process doesn't start until I launch the target app from the device where I posted.

  • From Instagram
    After posting, the modal closes immediately without the posting indication.
    I find the posting when I check it on the desktop.
    The posting process is completed without any problems.

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

@yasirkula
Copy link
Owner

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
Copy link
Author

wataru-hasegawa commented Dec 25, 2021

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

  • true
    After posting, the target app is launched and starts posting, and completes the process a few seconds later.

  • false
    The same behavior as before the code was added, the posting process will not start until the target app is launched.

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

@wataru-hasegawa
Copy link
Author

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

  • When launch
    The posting process starts and then I manually return to my app.

  • When not launch
    The behavior is as reported in this issue.
    The posting process doesn't start until I launch the target app myself.

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

@yasirkula
Copy link
Owner

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

@yasirkula
Copy link
Owner

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?

yasirkula added a commit that referenced this issue May 1, 2022
- Potential fix for rare "NSCallbackHelper is destroyed!" warnings
- Potential fix for #137
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants