Update DocumentsContract call.
Test: Builds properly. Bug: 36023174 Change-Id: I6d8c604a9660741dda1c997f949efd0f570cc506
This commit is contained in:
@@ -301,9 +301,9 @@ public class DocumentsSample extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create some documents
|
// Create some documents
|
||||||
Uri pic = DocumentsContract.createDocument(cr, doc, "image/png", "pic.png");
|
Uri pic = createDocument(cr, doc, "image/png", "pic.png");
|
||||||
Uri dir = DocumentsContract.createDocument(cr, doc, Document.MIME_TYPE_DIR, "my dir");
|
Uri dir = createDocument(cr, doc, Document.MIME_TYPE_DIR, "my dir");
|
||||||
Uri dirPic = DocumentsContract.createDocument(cr, dir, "image/png", "pic2.png");
|
Uri dirPic = createDocument(cr, dir, "image/png", "pic2.png");
|
||||||
|
|
||||||
log("created " + pic);
|
log("created " + pic);
|
||||||
log("created " + dir);
|
log("created " + dir);
|
||||||
@@ -322,13 +322,13 @@ public class DocumentsSample extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// And delete the first pic
|
// And delete the first pic
|
||||||
if (DocumentsContract.deleteDocument(cr, pic)) {
|
if (deleteDocument(cr, pic)) {
|
||||||
log("deleted untouched pic");
|
log("deleted untouched pic");
|
||||||
} else {
|
} else {
|
||||||
log("FAILED TO DELETE PIC");
|
log("FAILED TO DELETE PIC");
|
||||||
}
|
}
|
||||||
} else if (requestCode == CODE_RENAME) {
|
} 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);
|
log("rename result=" + newUri);
|
||||||
|
|
||||||
InputStream is = null;
|
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() {
|
private void clearLog() {
|
||||||
mResult.setText(null);
|
mResult.setText(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user