获取真实路径对于开放的安卓路径、真实

2023-09-05 23:14:15 作者:太酷会托网速

我开发一个的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

我希望你能成功。

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.

 
精彩推荐
图片推荐