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();
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();
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
.
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..
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.