Issue
Why doesn't this code work fine on devices with Android API level 30 (extras are null)? However with API level 29 the extras are not null and we get what we sent.
The extras we are sending are just one string.
We are launching the intent from Unity app (C#), but not sure if that's relevant.
Java Code in Android Studio
public void onResume() {
super.onResume();
Bundle extras = getIntent().getExtras();
if (extras != null) {
//not null in 29, null in 30
}
}
Unity(C#) Code
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
var bundle = "com.xxxxxx.xxxxx";
launchIntent=packageManager.Call<AndroidJavaObject("getLaunchIntentForPackage",bundle);
launchIntent.Call<AndroidJavaObject>("putExtra", "argument", "StringArgument");
ca.Call("startActivity", launchIntent);
Solution
I managed to find a fix for this issue. It seems the newer versions of Android have a separate permission layer for more secure intent action as per this link.
Basically I added this line to both applications’ AndroidManifest.xml files (Android Studio app and Unity app):
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />
Answered By - BratSlnko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.