简体   繁体   中英

Get Path File From Uri in android studio

I Cant Get Path File From Uri In Zip File Type Or APK file Type. In onActivityResult

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("*/*");

startActivityForResult(intent, KeyGallery);

//For Get Path

String picturePath = data.getData().getPath();

I receive /document/415:|

Please Help me

It's Work For Me!

Use:

 String path = data.getData().getPath() // "/mnt/sdcard/FileName.mp3" File file = new File(new URI(path));

or

String path = data.getData().toString() // "file:///mnt/sdcard/FileName.mp3" File file = new File(new URI(path));

You can use this function to get the file path.

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;
    }

Hope this helps! Happy Coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM