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 "Isn
t 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.
- Make Intent and IntentFilter match
- 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.
- Caller (API 33 or lower or higher) -> Target (API 32 or lower): works like Android 12, does not block
- 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.
- Remove all other information, such as Action, except for Component, from the explicit intent
- Change information such as Action in explicit intent to match IntentFilter
Related Posts
- How to download and build Android 13, AOSP
- Notification permission request, pop up notification in Android 13
- Resolve `Access blocked: ComponentInfo` error on Android 13
- Fix error "android gradle plugin requires java 11 to run. you are currently using java 1.8."
- Android - Vibration, Vibrator, VibrationEffect example
- How to get phone number in Android
- How to create Bugreports and Logcat with ADB in Android
- Clear application user data with ADB in Android
- How to disable/enable apps with ADB in Android
- How to find PID of a package with adb in Android
- How to grant/revoke permissions with adb in Android
- How to install an apk(app) with adb in Android
- How to kill a process/package from ADB in Android
- How to transfer files using adb push/pull command in Android
- How to capture the screen from adb in Android
- How to uninstall/install system apps from adb in Android
- How to change Settings values from adb in Android
- How to Factory reset with ADB in Android
- How to get logcat from ADB command in Android
- How to capture Heap Dump from app with ADB in Android
- How to force stop an app with adb in Android
- How to start/stop a service from adb in Android
- How to send/broadcast an intent from adb command in Android
- How to start an activity from adb in Android
- How to generate input from adb in Android
- How to check SQLite DB table in Android Studio
- How to get memory info and thread list from adb in Android
- Android - Uri, Scheme and SSP(Scheme Specific Part)
- How to parse a xml file with XmlResourceParser in Android
- Android - Signing an apk with Platfom key
- How to fix "Cleartext HTTP ... not permitted" for Android development
- How to fix "kvm permission denied" for Android Emulator
- Using ADB over Wifi for Android development