Example code to test renaming documents.

Bug: 12350110
Change-Id: I6be7bd1cd93b8c1c83f05496157534d879f2f223
This commit is contained in:
Jeff Sharkey
2014-05-21 22:25:18 -07:00
parent 6ccc20a0aa
commit 5214072d6c

View File

@@ -48,6 +48,7 @@ public class DocumentsSample extends Activity {
private static final int CODE_READ = 42;
private static final int CODE_WRITE = 43;
private static final int CODE_PICK = 44;
private static final int CODE_RENAME = 45;
private TextView mResult;
@@ -216,6 +217,19 @@ public class DocumentsSample extends Activity {
});
view.addView(button);
button = new Button(context);
button.setText("OPEN_DOC */* for rename");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, CODE_RENAME);
}
});
view.addView(button);
final ScrollView scroll = new ScrollView(context);
scroll.addView(view);
@@ -313,6 +327,19 @@ public class DocumentsSample extends Activity {
} else {
log("FAILED TO DELETE PIC");
}
} else if (requestCode == CODE_RENAME) {
final Uri newUri = DocumentsContract.renameDocument(cr, uri, "MEOW.TEST");
log("rename result=" + newUri);
InputStream is = null;
try {
is = cr.openInputStream(newUri);
log("read length=" + readFullyNoClose(is).length);
} catch (Exception e) {
log("FAILED TO READ", e);
} finally {
closeQuietly(is);
}
}
}