Test StorageVolume#createOpenDocumentTreeIntent
Also fix bug where persistent uri access was not taken for OPEN_DOCUMENT_TREE intents. Change-Id: Iccc3e2434e08e42fa84dc3ceb3fbfe1db1320180 Fixes: 119519300 Test: manually using ApiDemos Content > Storage > Documents
This commit is contained in:
@@ -23,6 +23,9 @@ import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.StorageVolume;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.util.Log;
|
||||
@@ -217,6 +220,19 @@ public class DocumentsSample extends Activity {
|
||||
});
|
||||
view.addView(button);
|
||||
|
||||
button = new Button(context);
|
||||
button.setText("OPEN_DOC_TREE primary volume initial uri");
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = getSystemService(StorageManager.class)
|
||||
.getPrimaryStorageVolume()
|
||||
.createOpenDocumentTreeIntent();
|
||||
startActivityForResult(intent, CODE_TREE);
|
||||
}
|
||||
});
|
||||
view.addView(button);
|
||||
|
||||
button = new Button(context);
|
||||
button.setText("OPEN_DOC */* for rename");
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@@ -285,6 +301,11 @@ public class DocumentsSample extends Activity {
|
||||
closeQuietly(os);
|
||||
}
|
||||
} else if (requestCode == CODE_TREE) {
|
||||
try {
|
||||
cr.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
} catch (SecurityException e) {
|
||||
log("FAILED TO TAKE PERMISSION", e);
|
||||
}
|
||||
// Find existing docs
|
||||
Uri doc = DocumentsContract.buildDocumentUriUsingTree(uri,
|
||||
DocumentsContract.getTreeDocumentId(uri));
|
||||
|
||||
Reference in New Issue
Block a user