Home > database >  Android: android.content.ActivityNotFoundException: No Activity found to handle Intent
Android: android.content.ActivityNotFoundException: No Activity found to handle Intent

Time:11-29

I receive this error;

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK cat=[android.intent.category.OPENABLE] dat=content://media/external/audio/media }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2007)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4586)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:712)
        at android.app.Activity.startActivityForResult(Activity.java:4544)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:693)
        at com.emresaritas.basicmediaplayer.MainActivity.openMedia(MainActivity.java:65)
        at com.emresaritas.basicmediaplayer.MainActivity$2.onClick(MainActivity.java:59)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25885)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Code;

public void openMedia(){
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI).addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, PICK_MEDIA);
}

Manifest;

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.BasicMediaPlayer">
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/title_activity_main"
        android:theme="@style/Theme.BasicMediaPlayer.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

I've tried to change intent actions and activity structure but couldn't solve my problem. I'm trying to use intent to let user select a file from the storage.

CodePudding user response:

Try this once

public void openMedia(){
    Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI).addCategory(Intent.CATEGORY_OPENABLE);
    pickIntent.setType("video/*");//Add as per your requirement 
    startActivityForResult(pickIntent, PICK_MEDIA);
}

startActivityForResult is deprecated so new way

public void openMedia(){
    Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI).addCategory(Intent.CATEGORY_OPENABLE);
    pickIntent.setType("video/*");//Add as per your requirement
    someActivityResultLauncher.launch(pickIntent);
}

// You can do the assignment inside onAttach or onCreate, i.e, before the activity is displayed
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
        new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if (result.getResultCode() == Activity.RESULT_OK) {
                    // There are no request codes
                    Intent data = result.getData();
                    doSomeOperations();
                }
            }
        });

CodePudding user response:

Solved.

I still don't know why i was getting this error but i done this;

  1. Adding <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> line to intent-filter.
  2. I was using Android TV emulator (API 28) and changed that to API Tiramisu.

Probably it was some android api level problem.

  • Related