Android: open the audio selection dialog

I need to allow the user to select an audio file from his media library.

Here is what I am trying to do:

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

But I get the 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 safe, I also tried INTERNAL_CONTENT_URI , but the result is similar.

How can i achieve this?

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

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

+4
source share
1 answer

Well, I saw in LogCat what happens when I open the music selection 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, only notification sounds, then I need to add extra ones, just like this:

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

All Articles