Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从驱动器文件的URI内容获取输入流_Android_Android Contentresolver_Drive - Fatal编程技术网

Android 如何从驱动器文件的URI内容获取输入流

Android 如何从驱动器文件的URI内容获取输入流,android,android-contentresolver,drive,Android,Android Contentresolver,Drive,当我从Box Drive云存储中选择文件时,我得到的URI如下:content://com.box.android.documents/document/file%2C32851356501 我无法从其URI获取输入流。这是一个例外 意思是说,当我获得URI时,我可以从URI内容中获取输入流,如下所示:file:///storage/emulated/0/Android/data/com.box.android/241547485/cache/working/32851356501_e428a6

当我从Box Drive云存储中选择文件时,我得到的URI如下:content://com.box.android.documents/document/file%2C32851356501 我无法从其URI获取输入流。这是一个例外

意思是说,当我获得URI时,我可以从URI内容中获取输入流,如下所示:file:///storage/emulated/0/Android/data/com.box.android/241547485/cache/working/32851356501_e428a6934c285ed493f9c85acf9ab725e6f8f769/backend_1.png

以下是我从URI获取输入流的代码:

InputStream inputStream = null;
Uri uri = data.getData();
Log.e(TAG, "File Uri: " + uri.toString());
String mimeType = getApplicationContext().getContentResolver().getType(uri);
Log.e(TAG, "File Uri Mime: " + mimeType);

Cursor returnCursor =  getContentResolver().query(uri, null, null, null, null);

try {
    //inputStream = new FileInputStream(uri.getPath());
    inputStream = getContentResolver().openInputStream(uri);

} catch (FileNotFoundException e2) {
    // TODO Auto-generated catch block

    e2.printStackTrace();
}

如果数据是我的onActivityResult中的意图数据。

请阅读本论坛的更多帖子。不久前,有人对box也有同样的问题。我认为
/文件%2C32851356501
中的%2C是罪魁祸首。请改用/代替。@greenapps。我将字符替换为%to/。现在我得到的异常需要android.permission.MANAGE_文档或grantUriPermission()。我已经在Manifeat中添加了此代码
,但仍然不走运。Box drive应该授予权限。你找到另一个帖子了吗?为什么使用
googlecloudstorage
标签而不是
box-drive
?如果它存在的话。抱歉,我没有安装盒式驱动器,因此无法测试它。