0

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")
    }
}
  • "It is working fine upto android 12" -- there is no requirement for every single Android app on the planet to offer an `ACTION_VIEW` activity for an `https` `Uri`. For the *vast* majority of apps, your code will fail on all versions of Android. – CommonsWare May 17 '23 at 10:55
  • @CommonsWare you mean if you are creating activity whose intention is to render url like https then it is not required that activity should be declared with action of android.intent.action.VIEW ? Like what if developer want to allow to show it in option of view ? – jayesh gurudayalani May 17 '23 at 11:06
  • @jayeshgurudayalani: No. I mean that the code in the question assumes that if an app can be launched, it also has an `ACTION_VIEW` activity that supports an `https` `Uri`. That is not the case. For example, do you believe that every calculator app ever created in the history of Android has an `ACTION_VIEW` activity that supports an `https` `Uri`? – CommonsWare May 17 '23 at 12:29
  • Okay i got your point @CommonsWare . Thanks for clarification and you are right .. – jayesh gurudayalani May 17 '23 at 12:35

0 Answers0