This Java method allow to launch another Android app using an intent with a package name, with a fix for Android 13 and later. Add section to your manifest or permission QUERY_ALL_PACKAGES. Please note the Google Play Developer Policy regarding restrictions on the use of this permission.
Last active
January 21, 2024 13:34
-
-
Save 201949/295f6402537d6da28f8176eb32d43aed to your computer and use it in GitHub Desktop.
Launch another Android app using an intent with a package name, with a fix for Android 13 and later
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Launch another Android app using an intent with a package name, with a fix for Android 13 and later. Java code. | |
public void startNewActivity(Context context, String packageName) { | |
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName); | |
//Fix for Android 13 | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { | |
intent.addCategory(Intent.CATEGORY_LAUNCHER); | |
} | |
if (intent == null) { | |
// Bring user to the market or let them choose an app, package is not installed | |
intent = new Intent(Intent.ACTION_VIEW); | |
intent.setData(Uri.parse("market://details?id=" + packageName)); | |
} | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(intent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:tools="http://schemas.android.com/tools" | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
... | |
<queries> <!-- name the required packages --> | |
<package android:name="com.your.company.your.app"/> | |
<package android:name="com.other.company.other.app"/> | |
</queries> | |
... | |
</manifest> | |
<!-- OR --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:tools="http://schemas.android.com/tools" | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
... | |
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" | |
tools:ignore="QueryAllPackagesPermission" /> | |
... | |
</manifest> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment