I am using Nativescript 8.4 and I am trying to launch an application that does a very specific task. The following code works correctly on Android 8 and 9 but not on version 12:
My AndroidManifest.xml sets the intent-filter with the correct permissions (at least for Android 8 and 9)
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Here is the code that successfully launches the App for Android 8 and 9 but not on Android 12:
private launchApp() {
const cntxt = Utils.android.getApplicationContext();
const pm = cntxt.getPackageManager();
const packageName = "com.vms.android.theAppThtatIamTryingToInterface";
let intent = pm.getLaunchIntentForPackage(packageName);
if (intent){ // Add extra data
// works on Android 8 and 9 but not on 12
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setAction(android.content.Intent.ACTION_SEND);
intent.putExtra("mode", 0); //start dex mode
console.log('Before starting intent');
intent.putExtra("android.intent.extra.TEXT", this.getTransaction());
context.startActivity(intent);
}else{
console.log("Intent could not be created for", packageName);
}
}
The call to pm.getLaunchIntentForPackage(packageName) returns null on Android 12 but correctly returns the intent for Android 8 and 9
What am I missing?
I have tried getting the context from Utils.android.getApplicationContext() instead of the applicationModule.android.context but that did not work.
Additionally, I changed app.gradle to a higher SDK but that did not work either:
android {
compileSdkVersion 32
buildToolsVersion "32.0.0"
ndkVersion ""
defaultConfig {
minSdkVersion 17
targetSdkVersion 32
// Version Information
versionCode 1
versionName "1.0.0"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Ramon Murillo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.