我想瀏覽所有的音頻文件,但我越來越像錯誤應用程序可以執行此操作..這是我的代碼瀏覽活動...Android:沒有應用程序執行此操作,爲什麼?
- > private static final int SELECT_MUSIC = 1;
String selectedImagePath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button) findViewById(R.id.browse)).setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("music/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), SELECT_MUSIC);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_MUSIC) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = {MediaStore.Images.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);
}
我也有添加權限menifest文件:: READ_PHONE_STATE 有什麼問題呢?任何想法?
謝謝..
我也試過設備,但結果是一樣的。我該怎麼辦? – Piyush 2011-02-15 05:53:21