2013-05-31 1 views
2

음악 플레이어에서 선택한 파일의 파일 이름을 얻는 방법을 알고 싶습니다. 코딩 과정에서 음악 플레이어의 mp3 파일을 선택하고 데이터를 의도에서 가져 와서 URI에 할당합니다./1 또는 경로 내가 .kindly이 one.Here를 해결하는 데 도움이 MP3 파일의 파일 이름을 얻을 수 없습니다/2는 참조기본 음악 플레이어에서 android 에뮬레이터에서 파일 이름을 얻는 방법?

내 코드를 비스 경로처럼, 음악 플레이어 재생 목록에서 위치를 선택
//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); 

// 파일 이름 가져 오기

String mPath = null; 
      Uri mToneCaptureUri; 
      mToneCaptureUri = data.getData();    
      mPath = mToneCaptureUri.getPath(); // from File ManagerF 
        setPath(mPath); 

답변

3

가 onActivityResult를

mpath = getPath(data.getData()); 
+0

에 전체 경로와 파일 이름

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

사용이 얻기'managedQuery'는 이제 사용되지 않습니다! – Arash

관련 문제