Dmitry Frank
Dmitry Frank

Reputation: 10757

Android: open dialog for select audio

I need to allow user to select some audiofile from his media library.

Here's what I'm trying to do:

        Intent tmpIntent = new Intent(
              Intent.ACTION_PICK,
              android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
              );

        startActivityForResult(tmpIntent, 0);

But I get error:

08-20 17:44:35.444: E/AndroidRuntime(3773): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://media/external/audio/media }

To be on the safe side, I also tried INTERNAL_CONTENT_URI, but result is similar.

How can I achieve this?

UPD: by the way, if I try to pass URI to get images (i.e. android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), then it works: image open dialog is opened.

UPD2: Just tried this on emulator - my code works! But on two devices it doesn't (SE Xperia Neo and some Acer). But if I try the second variant from this answer, then I got menu with all my existing file-managers, and with "Music select" too! But I need to write Intent just to open this "Music select".

Upvotes: 4

Views: 5890

Answers (1)

Dmitry Frank
Dmitry Frank

Reputation: 10757

Well, I have seen in LogCat what happens when I open music select dialog, and I got what I need. This code works for me:

     Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
     startActivityForResult(tmpIntent, 0);

If I want to get, say, notifications sounds only, then I need to put extra, just like that:

     Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
     tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
     startActivityForResult(tmpIntent, 0);

Upvotes: 4

Related Questions