Resolve `Access blocked: ComponentInfo` error on Android 13

In Android 13, I tried to run the activity of another app with startActivity(), but the app was terminated with the following exception.

10-23 05:43:05.891   608  1743 W PackageManager: Access blocked: ComponentInfo{com.example.memorynotes/com.example.memorynotes.MainActivity}

10-23 05:43:05.893  8669  8669 D AndroidRuntime: Shutting down VM
10-23 05:43:05.895  8669  8669 E AndroidRuntime: FATAL EXCEPTION: main
10-23 05:43:05.895  8669  8669 E AndroidRuntime: Process: com.example.myapplication, PID: 8669
10-23 05:43:05.895  8669  8669 E AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.memorynotes/com.example.memorynotes.MainActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?

The cause is that the activity that should be executed was blocked as a log called Access blocked was output when the intent was executed.

In this article, we will look at the changes in Android 13 for Intent and how to solve it.

1. Android 13 changes: Intent not matching IntentFilter

Android Developer with the title Intent filters block non-matching intents 13 changes were introduced.

In Android 13, when executing a component such as Activity or Service with an intent, it is not executed if the intent does not match the IntentFilter defined in the component.

1.1 Differences between Android 12 and Android 13

Usually implicit intents are only fired when they match an IntentFilter, so were talking about "Isnt that obvious?", "Isn`t this how it originally worked?" You may think.

However, explicit intents differ between Android 13 and Android 12.

Consider executing the MainActivity of MainActivity defined in the Manifest below with the code below. Android 12 will work, but Android 13 may not due to this behavior change

val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.component = ComponentName("com.example.memorynotes",
    "com.example.memorynotes.MainActivity")
startActivity(intent)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.memorynotes">

    <application ... />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

2. When changes are applied

In Android 13, this change only applies when running the app`s component with Target SDK API 33. In other words, the target SDK API of the app executing startActivity() is not important, and whether changes are applied or not depends on the target API of the app that has the activity being executed.

In other words,

  • This change is applied when the target API of the app that has the component to be executed is 33 or higher.
  • When the target API of the app that has the component to be executed is 32 or lower, this change will not be applied.

3. Troubleshooting Room

In the situation where this change is applied, if you do not want to block the execution of the Activity, you can change it as follows.

  1. Make Intent and IntentFilter match
  2. Delete all information such as Action and Category in Intent other than Component.

3.1 How to make Intent and IntentFilter match

Activity is executed when the intent and intent filter match as shown below.

val intent = Intent()
intent.action = Intent.ACTION_MAIN
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.component = ComponentName("com.example.memorynotes",
    "com.example.memorynotes.MainActivity")
startActivity(intent)

3.2 Delete all information such as Action and Catagory other than Component in Intent.

As shown below, if you execute an intent that has no information other than a component in the intent, the Activity is executed even if the Action etc. do not match the IntentFilter.

val intent = Intent()
intent.component = ComponentName("com.example.memorynotes",
    "com.example.memorynotes.MainActivity")
startActivity(intent)

4. Summary

Applies to apps whose Target is API 33 or higher as shown below.

  1. Caller (API 33 or lower or higher) -> Target (API 32 or lower): works like Android 12, does not block
  2. Caller (API 33 or lower or higher) -> Target (API 33 or higher): Android 13 changes applied, may be blocked

In the case of an implicit intent, since Android 12 has to match the intent to be executed, there is no special consideration in Android 13. In the case of an explicit intent, in Android 13, even if Component is set, if information such as Action does not match the IntentFilter, it is not executed. changed not to.

To modify the component to run, you need to change it as follows.

  1. Remove all other information, such as Action, except for Component, from the explicit intent
  2. Change information such as Action in explicit intent to match IntentFilter

Related Posts

codechachaCopyright ©2019 codechacha