2

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/uri 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

Community
  • 1
  • 1
Stefan Olsson
  • 617
  • 3
  • 16
  • 32

2 Answers2

2

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.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
  • Aha, true, the File-class should be able to do the trick, this might be the other solution can not work with my dialog box, thanks – Stefan Olsson May 23 '11 at 15:21
2

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();
        ...
    }
}
ernazm
  • 9,208
  • 4
  • 44
  • 51