OHAI
I’ve not had much chance to play around with the JNI bridge before now and of-course I run smack into a problem.
What I need to achieve is basically to install an APK via an Intent - like so:
Intent intent = new Intent ("android.intent.action.VIEW");
Uri uri = Uri.parse (apkURIString);
intent.setDataAndType (uri, "application/vnd.android.package-archive");
startActivity (intent);
However I’m facing some difficulty when implementing this via the AndroidJavaObject/Class interface - particularly in the setDataAndType call where the uri is passed in.
For debugging, I’ve split that call into two - setData followed by setType:
AndroidJavaObject intent = new AndroidJavaObject ("android.content.Intent", "android.intent.action.VIEW");
AndroidJavaClass uriClass = new AndroidJavaClass ("android.net.Uri");
AndroidJavaObject uri = uriClass.CallStatic<AndroidJavaObject> ("parse", updatePath);
intent.Call ("setData", uri);
intent.Call ("setType", "application/vnd.android.package-archive");
AndroidJavaClass unityPlayerClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject> ("currentActivity");
currentActivity.Call ("startActivity", intent);
When running this, I get as far as the setData call, at which point the JNI layer bails out with a Java exception:
E/Unity ( 616): System.Exception: java.lang.NoSuchMethodError: no method with name='setData' signature='(Landroid.net.Uri$StringUri;)V' in class Landroid/content/Intent;
E/Unity ( 616): at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
E/Unity ( 616): at UnityEngine.AndroidJNISafe.GetMethodID (IntPtr obj, System.String name, System.String sig) [0x00000] in <filename unknown>:0
E/Unity ( 616): at UnityEngine._AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.String signature, Boolean isStatic) [0x00000] in <filename unknown>:0
E/Unity ( 616): at UnityEngine.AndroidJNIHelper.GetMethodID (IntPtr javaClass, System.String methodName, System.String signature, Boolean isStatic) [0x00000] in <filename unknown>:0
E/Unity ( 616): at UnityEngine._AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x00000] in <filename unknown>:0
E/Unity ( 616): at UnityEngine.AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x0000
I am particularly curious about the parameter being sent in the call signature “Landroid.net.Uri$StringUri;” - as a bit of digging would seem to indicate that “$” indicates a contained class. So is my passed AndroidJavaObject being resolved into the wrong type somehow?
Looking at the disassembly of the .Call method, it seems that this is indeed the expected way to pass reference parameters to Java land, so where did I get it wrong?
Since it breaks down here I also fully expect the later call to activity.startActivity - taking the intent reference - to fail in the same manner.
Any pointers would be greatly appreciated.