安卓:开放的对话框中选择音频 [英] Android: open dialog for select audio
问题描述
我需要让用户从自己的媒体库中的一些audiofile的。
I need to allow user to select some audiofile from his media library.
下面就是我想要做的:
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 }
要在安全方面,我也试过 INTERNAL_CONTENT_URI
,但结果是类似的。
To be on the safe side, I also tried INTERNAL_CONTENT_URI
, but result is similar.
我怎样才能做到这一点?
How can I achieve this?
UPD:顺便说一句,如果我试图通过URI获得的图像(即 android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
),那么它的工作原理:像打开的对话框打开。
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:只是尝试这样的模拟器 - 我的code的作品!但它没有两个设备(SE XPERIA neo和一些宏碁)。但如果我尝试从第二个变种<一个href=\"http://stackoverflow.com/questions/10461065/how-to-pickup-an-audio-files-path-or-uri-from-device-in-android/10461112#10461112\">this回答,然后我得到了所有我现有的文件经理菜单,并用选择音乐呢!但我只是需要写意图打开这个选择音乐。
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".
推荐答案
好吧,我在LogCat中所看到的,当我打开音乐选择对话框中会发生什么,我得到了我所需要的。这code为我工作:
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);
这篇关于安卓:开放的对话框中选择音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!