开发者

Android Using mediaStore

The Android platform have a number of "ready easy use" dialog such as ProgressDialog, DatePickerDialog and TimePickerDialog, these are fire and wait boxes, that is, they handle UI, right data and return something.

Is there a similar dialogbox for the mediastorage ?

I want something like "AudioFilePickerDialog" which shows a UI to the user where the user pick a audio file and return the path/ur开发者_如何学JAVAi to the audio file.

Do I need to build this dialog box up myself or does it exists somewhere ?

One of the few examples I have found is Given an Android music playlist name, how can one find the songs in the playlist?

but this handles playlists.

/Stefan


I found a tutorial for something like a FileChooser here. You should be able to make it only show Music-Files (like .mp3).

Also, to browser the SDcard of your Android Device, you can use the standard Java File-class, like in normal Java.


Try this

Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_MEDIA);//REQUEST_MEDIA is some const int to operate with in onActivityResult

here you'll be brought a dialog (activity tbh) to choose an audio from mediastore.
Handle the result in onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_MEDIA && resultCode == RESULT_OK) {
        String audioID = data.getDataString();
        ...
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜