diff options
| author | Ben Lin <linben@google.com> | 2017-03-09 11:00:50 -0800 |
|---|---|---|
| committer | Ben Lin <linben@google.com> | 2017-03-09 11:04:44 -0800 |
| commit | 9cf5fd65aa415939854bc900f29ced7c70ee27a1 (patch) | |
| tree | 65ba3749211ac9d71c57005c6934007e496db4a4 /samples/ApiDemos | |
| parent | d69f0a2fd8c6f8d2e0ce3c8db2a59425d4174f7d (diff) | |
| download | android_development-9cf5fd65aa415939854bc900f29ced7c70ee27a1.tar.gz android_development-9cf5fd65aa415939854bc900f29ced7c70ee27a1.tar.bz2 android_development-9cf5fd65aa415939854bc900f29ced7c70ee27a1.zip | |
Update DocumentsContract call.
Test: Builds properly.
Bug: 36023174
Change-Id: I6d8c604a9660741dda1c997f949efd0f570cc506
Diffstat (limited to 'samples/ApiDemos')
| -rw-r--r-- | samples/ApiDemos/src/com/example/android/apis/content/DocumentsSample.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/content/DocumentsSample.java b/samples/ApiDemos/src/com/example/android/apis/content/DocumentsSample.java index a00974b12..9f3f4699d 100644 --- a/samples/ApiDemos/src/com/example/android/apis/content/DocumentsSample.java +++ b/samples/ApiDemos/src/com/example/android/apis/content/DocumentsSample.java @@ -301,9 +301,9 @@ public class DocumentsSample extends Activity { } // Create some documents - Uri pic = DocumentsContract.createDocument(cr, doc, "image/png", "pic.png"); - Uri dir = DocumentsContract.createDocument(cr, doc, Document.MIME_TYPE_DIR, "my dir"); - Uri dirPic = DocumentsContract.createDocument(cr, dir, "image/png", "pic2.png"); + Uri pic = createDocument(cr, doc, "image/png", "pic.png"); + Uri dir = createDocument(cr, doc, Document.MIME_TYPE_DIR, "my dir"); + Uri dirPic = createDocument(cr, dir, "image/png", "pic2.png"); log("created " + pic); log("created " + dir); @@ -322,13 +322,13 @@ public class DocumentsSample extends Activity { } // And delete the first pic - if (DocumentsContract.deleteDocument(cr, pic)) { + if (deleteDocument(cr, pic)) { log("deleted untouched pic"); } else { log("FAILED TO DELETE PIC"); } } else if (requestCode == CODE_RENAME) { - final Uri newUri = DocumentsContract.renameDocument(cr, uri, "MEOW.TEST"); + final Uri newUri = renameDocument(cr, uri, "MEOW.TEST"); log("rename result=" + newUri); InputStream is = null; @@ -343,6 +343,33 @@ public class DocumentsSample extends Activity { } } + private Uri createDocument(ContentResolver resolver, Uri documentUri, String mimeType, + String displayName) { + Uri uri; + try { + uri = DocumentsContract.createDocument(resolver, documentUri, mimeType, displayName); + } catch (Exception e) { + uri = null; + } + return uri; + } + + private boolean deleteDocument(ContentResolver resolver, Uri documentUri) { + try { + return DocumentsContract.deleteDocument(resolver, documentUri); + } catch (Exception e) { + return false; + } + } + + private Uri renameDocument(ContentResolver resolver, Uri uri, String newName) { + try { + return DocumentsContract.renameDocument(resolver, uri, newName); + } catch (Exception e) { + return null; + } + } + private void clearLog() { mResult.setText(null); } |
