[BUG] Unable to get document correct URI with Intent.ACTION_CREATE_DOCUMENT and FLAG_GRANT_PERSISTABLE_URI_PERMISSION
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 4.2k
- Forks
- 3.1k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 7
Description
Actual behaviour
I am trying to use SAF to save a file directly in owncloud and the idea is to keep the URI returned so that I can eventually overwrite it.
currently the code is
Intent fileSelector = new Intent(Intent.ACTION_CREATE_DOCUMENT);
fileSelector.addCategory(Intent.CATEGORY_OPENABLE);
fileSelector.setType("text/*");
fileSelector.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
fileSelector.putExtra(Intent.EXTRA_TITLE, "bookmarks.html");
upon receipt of the intent:
public void onIntentCompleted(WindowAndroid window, int resultCode, Intent data) {
if (data == null) return;
Uri filePath = data.getData();
ContentResolver resolver = ContextUtils.getApplicationContext().getContentResolver();
resolver.takePersistableUriPermission(filePath, Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
...
I receive as a filePath = content://org.owncloud.documents/document/-1. reselecting the same generated document instead returns a correct id
Expected behaviour
receive a value like content://org.owncloud.documents/document/<IDDOCUMENT>
Can this problem be reproduced with the official owncloud server?
yes, actually I have content://org.owncloud.documents/document/-1
Environment data
Android version: A9
Device model: BLN-L22
Stock or customized system:
Customized: Omni Rom
ownCloud app version:
version 2.16 release 0259f7bef
ownCloud server version:
ownCloud 10.4.1 (stable)
Thanks for your help
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the flow using Intent.ACTION_CREATE_DOCUMENT and the onIntentCompleted handler, then inspect the URI returned by ContentResolver.takePersistableUriPermission. Compare the initial URI with the URI returned after reselecting the document and verify that the created document receives its actual ID instead of -1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100