Sinigami
Sinigami

Reputation: 449

Intent.ACTION_PICK crashed with type "audio/*"

Code:

 Intent intent = new Intent(Intent.ACTION_PICK);
 intent.setType("audio/*");

 startActivityForResult(intent, 1);

Result:

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK typ=audio/* }
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1638)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
            at android.app.Activity.startActivityForResult(Activity.java:3258)
            at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:854)
            at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:889)
            at org.test.sample.TestFragment.onClick(TestFragment.java:58)
            at android.view.View.performClick(View.java:3538)
            at android.view.View$PerformClick.run(View.java:14330)
            at android.os.Handler.handleCallback(Handler.java:608)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:156)
            at android.app.ActivityThread.main(ActivityThread.java:4977)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)

With types "video/*" & "image/*" works correctly.

For now for audio I'm using:

new Intent(Intent.ACTION_PICK, droid.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);

Upvotes: 2

Views: 1849

Answers (3)

BarmanInfo
BarmanInfo

Reputation: 392

Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Audio "),  GALLERY_AUDIO);

Upvotes: 2

Cheerag
Cheerag

Reputation: 435

use below

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

Upvotes: 1

Tomer Mor
Tomer Mor

Reputation: 8028

Yes, it's crash because there is no Activity to handle such an intent ACTION,

what exactly are you trying to achieve ?

moreover you can check if there is activity that can handle such an intent with

intent.resolveActivity(pm)

Upvotes: 0

Related Questions