Reputation: 3830
I want to know how to get the file name of the selected file in music player,In my coding ,i was selected the mp3 file from music player and getting the data from intent and assign it to uri,where i only get the selected position in music player playlist,like Path/1 or Path/2 ,where i was not able to get the FileName of the Mp3 File .kindly help me to solve this one.Here bis my code for Reference
//for opening the file
Intent intent = new Intent();
intent.setType("audio/mp3");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Complete action using"),
PICK_FROM_FILE);
//Get FileName
String mPath = null;
Uri mToneCaptureUri;
mToneCaptureUri = data.getData();
mPath = mToneCaptureUri.getPath(); // from File ManagerF
setPath(mPath);
Upvotes: 2
Views: 774
Reputation: 3830
Getting full path and file name
public String getPath(Uri uri) {
String[] projection = { MediaStore.Audio.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
use this on onActivityResult
mpath = getPath(data.getData());
Upvotes: 3