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

SavePayload with an album name won't work on some Android devices #95

Closed derwaldgeist closed 3 years ago

derwaldgeist commented 4 years ago

I noticed that on my Xiaomi Mi9, SavePayload only works if I call it without an album name. Once I set a name, the app crashes telling me the app is only allowed to write to the default album.

Not sure if this is a bug or just the default behavior of some devices? But I think it would be worth mentioning this in the docs.

On an iPhone X, it works fine though.

olokobayusuf commented 4 years ago

Can you share the logs? And what version of Android is your Xiaomi running?

derwaldgeist commented 4 years ago

Update: I now implemented my own Permission management to request access to external storage. But even when it is granted, I am getting this crash:

2020-06-28 13:34:13.244 27112-27741/com.marblear.prototype.staging E/AndroidRuntime: FATAL EXCEPTION: SavePayload Commit Thread
    Process: com.marblear.prototype.staging, PID: 27112
    java.lang.IllegalArgumentException: Primary directory Marble not allowed for content://media/external/images/media; allowed directories are [DCIM, Pictures]
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
        at android.content.ContentProviderProxy.insert(ContentProviderNative.java:481)
        at android.content.ContentResolver.insert(ContentResolver.java:1844)
        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:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:224)
        at android.os.HandlerThread.run(HandlerThread.java:67)
derwaldgeist commented 4 years ago

Android version is 10 QKQ1.190825.002

olokobayusuf commented 4 years ago

I just realized that I haven't addressed this. My bad; the fix is pretty simple. I'll create a PR with the fix later today or tomorrow.

derwaldgeist commented 4 years ago

Awesome, sounds good! This is not as urgent as the video fix was.

BTW: If you want to see our video feature in action, it's now live in the app stores (links on marblear.com). Our users love this.

vinhui commented 4 years ago

Any update for this?

olokobayusuf commented 4 years ago

I've added a fix for this in #97. Until the PR is merged, you can clone the project, switch to the android-23 branch, and copy the "NatSuite" folder into your project (or export the folder as a Unity package and import it to your project).

vinhui commented 4 years ago

Sorry for the late reaction, this branch still gives me a hard crash with the following in the logcat:

09-29 16:07:45.596  3153 27598 E DatabaseUtils: Writing exception to parcel
09-29 16:07:45.596  3153 27598 E DatabaseUtils: java.lang.IllegalArgumentException: Primary directory DCIM_null not allowed for content://media/external/images/media; allowed directories are [DCIM, Pictures]
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at com.android.providers.media.MediaProvider.ensureFileColumns(MediaProvider.java:2473)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at com.android.providers.media.MediaProvider.ensureUniqueFileColumns(MediaProvider.java:2284)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:2943)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3504)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at com.android.providers.media.MediaProvider.insert(MediaProvider.java:3386)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at android.content.ContentProvider$Transport.insert(ContentProvider.java:309)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:154)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at android.os.Binder.execTransactInternal(Binder.java:1056)
09-29 16:07:45.596  3153 27598 E DatabaseUtils:         at android.os.Binder.execTransact(Binder.java:1029)
09-29 16:07:45.602 25129 25806 E AndroidRuntime: FATAL EXCEPTION: SavePayload
09-29 16:07:45.602 25129 25806 E AndroidRuntime: java.lang.IllegalArgumentException: Primary directory DCIM_null not allowed for content://media/external/images/media; allowed directories are [DCIM, Pictures]
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.content.ContentProviderProxy.insert(ContentProviderNative.java:481)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.content.ContentResolver.insert(ContentResolver.java:1835)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at api.natsuite.natshare.SavePayload.lambda$commit$0$SavePayload(SavePayload.java:74)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at api.natsuite.natshare.-$$Lambda$SavePayload$Pw9qosDn6jOWCGYKHhmSllYVBr8.run(Unknown Source:4)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:883)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:100)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:237)
09-29 16:07:45.602 25129 25806 E AndroidRuntime:        at android.os.HandlerThread.run(HandlerThread.java:67)

DCIM_null is when no album name was passed, if it was passed then it's DCIM_My Album

olokobayusuf commented 4 years ago

I'll fix the null popping up when no album name is specified, but I'm surprised you're getting an underscore instead of a forward slash for the file separator:

https://github.com/natsuite/NatShare-API/blob/ddd50e2ec44d922412973c9ee99488326b281be1/Android/NatShare/src/main/java/api/natsuite/natshare/SavePayload.java#L61

This is very weird. In any case I'll replace it with a standard forward slash. Sorry for the inconvenience. The branch is still very much under development so I'm not surprised that some things break.

vinhui commented 4 years ago

I tested it on a Samsung S5e tablet if that helps.

olokobayusuf commented 3 years ago

This issue should be fixed now in #97 .

derwaldgeist commented 3 years ago

Awesome. Does this mean that we can set arbitrary library names now?

olokobayusuf commented 3 years ago

Awesome. Does this mean that we can set arbitrary library names now?

I'm not sure what you mean by arbitrary library names. If you're referring to albums/collections within the camera roll, then yes, you should be all set. Grab the release here.