Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a total hack, but here's what I did...</p> <p>So while playing with setting up a <a href="https://developer.android.com/reference/android/provider/DocumentsProvider.html" rel="nofollow">DocumentsProvider</a>, I noticed that the <a href="http://developer.android.com/samples/StorageProvider/src/com.example.android.storageprovider/MyCloudProvider.html" rel="nofollow">sample code</a> (in <code>getDocIdForFile</code>, around line 450) generates a unique id for a selected document based on the file's (unique) path relative to the specified root you give it (that is, what you set <code>mBaseDir</code> to on line 96).</p> <p>So the URI ends up looking something like:</p> <p><code>content://com.example.provider/document/root:path/to/the/file</code></p> <p>As the docs say, it's assuming only a single root (in my case that's <code>Environment.getExternalStorageDirectory()</code> but you may use somewhere else... then it takes the file path, starting at the root, and makes it the unique ID, prepending "<code>root:</code>". So I can determine the path by eliminating the <code>"/document/root:</code>" part from uri.getPath(), creating an actual file path by doing something like this:</p> <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) { // check resultcodes and such, then... uri = data.getData(); if (uri.getAuthority().equals("com.example.provider")) { String path = Environment.getExternalStorageDirectory(0.toString() .concat("/") .concat(uri.getPath().substring("/document/root:".length()))); doSomethingWithThePath(path); } else { // another provider (maybe a cloud-based service such as GDrive) // created this uri. So handle it, or don't. You can allow specific // local filesystem providers, filter non-filesystem path results, etc. } </code></pre> <p>I know. It's shameful, but it worked. Again, this relies on you using your <em>own</em> documents provider in your app to generate the document ID.</p> <p>(Also, there's a better way to build the path that don't assume "/" is the path separator, etc. But you get the idea.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload