获取真实路径对于开放的安卓 [英] Get Real Path For Uri Android
本文介绍了获取真实路径对于开放的安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发一个的VideoPlayer
。我转换 URI
A推出意图的字符串,它给了我内容://媒体/外部.....
。但我需要得到真实路径。
例如: /存储/ extSdcard ....
。
我如何做到这一点?
下面是如果需要我的code:
videoURI = getIntent()的getData();
vv.setVideoURI(videoURI);
videoName = videoURI.toString();
tvTitle.setText(videoName);
解决方案
您可以使用此$ C $下选择录象路径。
开放的URI = data.getData();
的String [] filePathColumn = {MediaStore.Images.Media.DATA};
光标光标= getContentResolver()查询(URI,filePathColumn,NULL,NULL,NULL);
如果(cursor.moveToFirst()){
INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
字符串yourRealPath = cursor.getString(参数:columnIndex);
} 其他 {
// boooo,光标不会有行...
}
cursor.close();
您可以参考以下链接对您有所帮助。
得到URI从mediastore <文件名和路径/ P>
我希望你能成功。
I am developing a VideoPlayer
. I convert the URI
of a launched intent to a string and it gives me content://media/external.....
. But I need to get the real path.
For example: /storage/extSdcard....
.
How do I do this?
Here is my code if needed:
videoURI = getIntent().getData();
vv.setVideoURI(videoURI);
videoName = videoURI.toString();
tvTitle.setText(videoName);
解决方案
you can use this code for selected vedio path.
Uri uri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
if(cursor.moveToFirst()){
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String yourRealPath = cursor.getString(columnIndex);
} else {
//boooo, cursor doesn't have rows ...
}
cursor.close();
you can refer the below link for your help.
Get filename and path from uri from mediastore
I hope you will success.
这篇关于获取真实路径对于开放的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文