Closed dthul closed 3 years ago
It is not possible to access files outside Application.persistentDataPath and Application.temporaryCachePath on Storage Access Framework. Even though you have a filepath, it is simply inaccessible. You must copy the file to one of the aforementioned locations to be able to share it.
Thanks for your reply! I am able to share the file using the following code which does not require any file path and works solely with the Uri from the media store:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/mp4");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(intent, null));
I wonder if this is something that UnityNativeShare would be able to support, or if we need to use our own sharing code similar to the one above.
I'm not planning to add raw Uri support to NativeShare because it is Android only and is a very specific requirement (it hasn't been needed before). You can modify NativeShare's source code to add this functionality or use your own sharing code as you've mentioned.
P.S. On Android 11, filepaths for media files will likely be accessible via File APIs again: https://developer.android.com/training/data-storage/shared/media#direct-file-paths. So setting requestLegacyExternalStorage to true in AndroidManifest (as explained in the documentation) might be another solution. Bu you'll need READ_EXTERNAL_STORAGE permission granted.
Thanks for all the hints! We'll decide whether to enable legacy external storage for Android 10 or go with the Uri approach.
Description of the bug
We switched to Android 10 / API Level 29 and had to adjust our file creation code to support the new scoped storage (which will become mandatory with Android 11). Before, we just did:
whereas now we do something more elaborate:
This will generate a content Uri like "content://...". Since UnityNativeShare doesn't understand those, I convert the Uri to a file path with the following code:
When trying to share such a Uri derived path, I get the following error:
The share is unsuccessful and the receiving app reports an error (for example WhatsApp says "The file format is not supported", while Gmail complains that it is "Unable to attach file.") I saw that there are two closed issues (#61, #85) which reported the same error but said that the share was successful. This is not the case for me.
Platform specs
Please provide the following info if this is a Unity 3D repository.