0

I got a audio file uri in onActivityResult but when i get a file from this URI it shows file not found exception and /directory/xxxx is not a absolute path.

Here is URI code : Uri muri=data.getData();

3 Answers3

1

There is no requirement that a Uri returned in onActivityResult() be a file that you can access directly. A Uri is not necessarily a File.

Please use openInputStream() on a ContentResolver to get an InputStream on the data represented by the Uri.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
-1

Try this..

Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("audio/*");
            startActivityForResult(i, GET_MP3);

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == GET_MP3) {
Uri selectedmp3 = data.getData();
                mp3_path = getpathmp3(selectedmp3);
}

private String getpathring(Uri path) {
        String result;
        Cursor cursor = getContentResolver()
                .query(path, null, null, null, null);
        if (cursor == null) {
            result = path.getPath();
            int name = result.lastIndexOf("/");
            mp3_name = result.substring(name + 1);
        } else {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);

            result = cursor.getString(idx);
            cursor.close();
            int name = result.lastIndexOf("/");
            mp3_name = result.substring(name + 1);
        }
        return result;
    }

The mp3_path is the path you will get..tell me after trying this..

-1

After Long Time Finally I Got Solution For this. i collected from Get real path from URI, Android KitKat new storage access framework this link @Paul Burke Answer.

Community
  • 1
  • 1