Reputation: 39
I am trying to launch an Application with use of Intent and PackageManager. It is working fine upto android 12 but due to some behaviour changes in android 13 it is throwing me an Exception i.e: ActivityNotFoundException. Complete Error message is as below:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.app.globalfitanywhere/com.app.globalfitanywhere.view.activity.SplashActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared ?
I had tried different solutions and did research on official Docs of Intents in Android. It says that we must have to match IntentFilters of both Apps to launch App but I am bit confused about this.
I am attaching my code here for reference. Do comment if you have any solution regarding the same.
Main Code to launch Second App:
private fun prepareToLaunchApp(appPackage: String) {
val isAppInstalled = appInstalledOrNot(appPackage)
if (isAppInstalled) {
val myAction: Uri =
Uri.parse("https://$appPackage?emailId=${preference.email}")// need to change this to nutrition
val packageManager = requireActivity().packageManager
val intent = packageManager.getLaunchIntentForPackage(appPackage)
if (intent != null) {
intent.action = Intent.ACTION_VIEW
intent.data = myAction
startActivity(intent)
}
} else {
shareApp(appPackage, requireActivity())
}
}
Manifest of App Launcher App
<activity
android:name=".ui.HomeActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
tools:ignore="LockedOrientationActivity" />
Manifest of Receiver App
<activity
android:name=".view.activity.SplashActivity"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Code to receive Intent from Launcher App
override fun onResume() {
super.onResume()
SharedPrefsManager.setString(GlobalKeys.UNIVERSAL_EMAIL_ID, "")
val intent = intent
val data1 = intent.data
if (data1 != null) {
val uri: Uri =
Uri.parse(intent.dataString)
emailId = uri.getQueryParameter("emailId").toString()
SharedPrefsManager.setString(GlobalKeys.UNIVERSAL_EMAIL_ID, emailId)
Log.e("###", "param userid==> $emailId")
}
}
Upvotes: 0
Views: 494