Skip to content

[Feature]: Support EXTRA_INITIAL_URI in termux documents provider #5279

Description

@AlainKnaff

Feature description

In Android, when an app wants to open a file picker, it has the possibility to specify a starting directory using the EXTRA_INITIAL_URI intent attribute.

However, for this to work, it needs help from the documents provider, which must implement a findDocumentPath method to break down that URL into a path how it can be reached from the root.

So, /data/data/com.termux/files/home/Photos/vacation would be broken down into root=content://com.termux.documents/root, path= [ "/data/data/com.termux/files/home", "/data/data/com.termux/files/home/Photos", "/data/data/com.termux/files/home/Photos/vacation" ]

Currently, termux doesn't provide this method, and an attempt to open a picker with one of termux's directories as an EXTRA_INITIAL_URI fails with the following exception in termux' logcat:

--------- beginning of main
08-25 18:43:58.562 8264 11800 E DatabaseUtils: Writing exception to parcel
08-25 18:43:58.562 8264 11800 E DatabaseUtils: java.lang.UnsupportedOperationException: findDocumentPath not supported.
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.provider.DocumentsProvider.findDocumentPath(DocumentsProvider.java:475)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.provider.DocumentsProvider.callUnchecked(DocumentsProvider.java:1348)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.provider.DocumentsProvider.call(DocumentsProvider.java:1168)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.content.ContentProvider.call(ContentProvider.java:2756)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.content.ContentProvider$Transport.call(ContentProvider.java:648)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:309)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.os.Binder.execTransactInternal(Binder.java:1364)
08-25 18:43:58.562 8264 11800 E DatabaseUtils: at android.os.Binder.execTransact(Binder.java:1323)

Additional information

the builtin com.android.externalstorage.documents documents provider (which handles /sdcard) has this feature, and so has my sftp saf provider lu.knaff.alain.sftp.documents since recently

Here is the documentation about the findDocumentPath method:

https://developer.android.com/reference/android/provider/DocumentsProvider#findDocumentPath(java.lang.String,%20java.lang.String)

In the use case relevant for EXTRA_INITIAL_URI, it is called with parent=null.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions