我尝试了很多代码获取PDF路径在android 11或12,但只工作在android 10或以下设备.你能帮我吗?我分享我的代码行
如此用心的呼唤
第一个
getPath调用方式如下
public String getPath(Uri uri) {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor == null) return null;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String s = cursor.getString(column_index);
cursor.close();
return s;
}
3条答案
按热度按时间vxqlmq5t1#
如果你想访问一个文件或者想从MediaStore返回的URI中获取文件路径,我有一个library,它可以处理你可能遇到的所有异常。这包括磁盘、内部磁盘和可移动磁盘上的所有文件。例如,当从Dropbox中选择一个文件时,该文件将被复制到你有完全访问权限的应用程序目录中,然后将返回复制的文件路径。
piv4azn72#
让我分享我的经验,以解决这个东西后,所以阅读所有。
从URI获取输入流
然后使用InputStream进行操作,就像我使用okHttp上传PDF一样
gajydyqb3#
这一个帮助在我的情况下对Android 11希望任何人得到这个有帮助的
如果R.string.app。