![](/img/trans.png)
[英]how to get absolute path file from an Uri content? Java Android Studio
[英]Get Path File From Uri in android studio
我無法從 Zip 文件類型或 APK 文件類型的 Uri 獲取路徑文件。 在 onActivityResult 中
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, KeyGallery);
//獲取路徑
String picturePath = data.getData().getPath();
我收到 /document/415:|
請幫我
這是為我工作!
采用:
String path = data.getData().getPath() // "/mnt/sdcard/FileName.mp3" File file = new File(new URI(path));
要么
String path = data.getData().toString() // "file:///mnt/sdcard/FileName.mp3" File file = new File(new URI(path));
您可以使用此 function 獲取文件路徑。
public static String getFilePath(Context context, Uri uri) {
String imagePath;
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor c = context.getContentResolver().query(uri, filePath, null, null, null);
assert c != null;
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
imagePath = c.getString(columnIndex);
c.close();
return imagePath;
}
希望這可以幫助! 快樂編碼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.