Stefan Olsson
Stefan Olsson

Reputation: 647

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

Upvotes: 2

Views: 3692

Answers (2)

ernazm
ernazm

Reputation: 9258

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

Upvotes: 2

Lukas Knuth
Lukas Knuth

Reputation: 25755

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.

Upvotes: 2

Related Questions