Adamantcheese / Kuroba

Kuroba - imageboard browser for Android
GNU General Public License v3.0
397 stars 29 forks source link

[BUG/DEV] Can't share an image when it is located in a SAF backed directory (not on sd-card) #549

Open K1rakishou opened 4 years ago

K1rakishou commented 4 years ago
2020-02-03 11:35:32.798 E/DatabaseUtils: Writing exception to parcel
    java.lang.UnsupportedOperationException: Unsupported Uri content://com.android.externalstorage.documents/tree/primary%3AKuroba-dev%2Ffiles/document/primary%3AKuroba-dev%2Ffiles/4chan/g/74603002_g_-_no_update_in_almost_a_yearIs_it_dead/wallhaven-5w3m83_shared.jpg
        at android.provider.DocumentsProvider.query(DocumentsProvider.java:927)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:267)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)
K1rakishou commented 4 years ago

Apparently something is wrong with the Uri, some bad symbols or something like that. After clearing the app data it works with the default paths:

2020-02-03 11:42:40.345 D/MediaProvider: Scanned /storage/emulated/0/Kuroba-dev/files/4chan/g/74603002_g_-_no_update_in_almost_a_yearIs_it_dead/wallhaven-5w3m83_shared.jpg as /storage/emulated/0/Kuroba-dev/files/4chan/g/74603002_g_-_no_update_in_almost_a_yearIs_it_dead/wallhaven-5w3m83_shared.jpg for content://media/external_primary/file/36151
K1rakishou commented 4 years ago

Alright, I think it's either impossible with SAF (because it kinda defeats the whole point of SAF and Scoped Storage) or I'm doing something wrong. Probably the former.

So in case of SAF we will probably have to use SAF file chooser so the user himself selects a file to share and then use the uri it returns. Gonna try this tomorrow.

K1rakishou commented 4 years ago

So this thing doesn't work in the release either and probably won't ever work the way it did because of SAF. SAF won't allow us sharing an Uri to a file into another app. We will have to use ACTION_OPEN_DOCUMENT for that which will show the file picker so the user will have to select a file by himself. They can probably be done by the next release since there were no complains about it meaning nobody uses it.

K1rakishou commented 4 years ago

Oh, apparently you can tell the SAF file picker to open itself in a specific directory:

Callers can set a document URI through DocumentsContract#EXTRA_INITIAL_URI to indicate the initial location of documents navigator. System will do its best to launch the navigator in the specified document if it's a folder, or the folder that contains the specified document if not.

K1rakishou commented 4 years ago

There is also this interesting thing:

To gain access to descendant (child, grandchild, etc) documents, use DocumentsContract#buildDocumentUriUsingTree(Uri, String) and DocumentsContract#buildChildDocumentsUriUsingTree(Uri, String) with the returned URI.