videokit-ai / natshare

Cross-platform social sharing for Unity Engine.
https://github.com/natmlx/videokit
Apache License 2.0
134 stars 28 forks source link

NatShare cannot save image to album on S10 5G #94

Closed derwaldgeist closed 4 years ago

derwaldgeist commented 4 years ago

A followup on #80 which has been marked as being resolved. On a Samsung S10 5G, the problem still persists even with the latest 1.2.3 release on the Unity Asset Store:

    Process: com.marblear.prototype.staging, PID: 13060
    java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=13060, uid=10231 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
        at android.os.Parcel.createException(Parcel.java:1966)
        at android.os.Parcel.readException(Parcel.java:1934)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
        at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
        at android.content.ContentResolver.insert(ContentResolver.java:1594)
        at api.natsuite.natshare.SavePayload.lambda$commit$0$SavePayload(SavePayload.java:90)
        at api.natsuite.natshare.-$$Lambda$SavePayload$0wjtSNJuMX77rkaraI8nWQBBikI.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:65)

Is works fine on a Xiaomi Mi9 and on an iPhone X.

I tried calling

Permission.RequestUserPermission(Permission.ExternalStorageWrite);

before executing the commit, but this didn't work either. The user won't get a request, and the app still crashes.

The only workaround so far is placing this before the call:

if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))

However, in this case even my Xiaomi won't write to the album anymore. Which works without the permission checkback. But only to the default album, as described in #95.

olokobayusuf commented 4 years ago

You need to enable writing to external storage in Player Settings.

derwaldgeist commented 4 years ago

Do you mean this flag?

image

It's already enabled.

olokobayusuf commented 4 years ago

In that case your app lacks runtime permissions. NatShare doesn't handle permissions on Android (given Unity's Permissions API), so I'd recommend filing a bug report with Unity since calling RequestUserPermission doesn't actually show a permission dialog. Also, you might be able to get it to show by deleting the app then reinstalling it.

derwaldgeist commented 4 years ago

Ok, I will try this. Is this mentioned in the docs? Anyways, thanks for your fast response on a Sunday.

olokobayusuf commented 4 years ago

Android permissions aren't mentioned because the issue you are facing seems rare (usually Player Settings fixes it). In any case, I'll mention it. The docs are still under construction.

derwaldgeist commented 4 years ago

Ok, I see. Maybe it's because I am handling all permissions myself on app startup, to make onboarding nicer.

derwaldgeist commented 4 years ago

I can confirm it works with implementing permission management. Awesome! Thanks again for the fast support.