我想知道,如果我启动以下Intent.ACTION_GET_CONTENT
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/zip");
startActivityForResult(intent, RequestCode.REQUEST_CHOOSE_BACKUP_FILE);
Run Code Online (Sandbox Code Playgroud)
并尝试通过以下方式读取意图返回的 Uri。
Uri uri = data.getData();
// Figure out extension
ContentResolver contentResolver = getContext().getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
final String extension = mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));
File temp = null;
try {
temp = File.createTempFile(Utils.getJStockUUID(), "." + extension);
} catch (IOException e) {
e.printStackTrace();
}
// Delete temp file when program exits.
temp.deleteOnExit();
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = getContext().getContentResolver().openInputStream(uri);
outputStream = new FileOutputStream(temp);
byte[] buffer = …Run Code Online (Sandbox Code Playgroud) android ×1