Problem with AndroidJavaObject - java.lang.NoSuchMethodError

Hi there.
I am trying to call some Java code to open a browser window on Oculus Quest.
Here is my script…

var intent = new AndroidJavaObject("android.content.Intent", "com.oculus.vrshell.intent.action.LAUNCH");

intent.Call("setPackage", "com.oculus.vrshell");
intent.Call("putExtra", "uri", "ovrweb://webtask?uri=" + url);
intent.Call("putExtra", "intent_data", new AndroidJavaClass("android.net.Uri").CallStatic<AndroidJavaObject>("parse", "systemux://browser"));

new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity").Call("sendBroadcast", intent);

Unfortunately, when I build and execute I get the following error…

02-19 08:47:51.388: E/Unity(8979): AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name=‘setPackage’ signature=‘(Ljava/lang/String;)V’ in class Landroid.content.Intent;
02-19 08:47:51.388: E/Unity(8979): (Filename: currently not available on il2cpp Line: -1)

Any idea what I am doing wrong?

Thanks in advance!
Dan

The only suspicious thing I see in your code is “com.oculus.vrshell.intent.action.LAUNCH”. What you have to pass when creating AndroidJavaObject is the actual value, not Java constant, make sure it is the correct one, including letter case.

Otherwise this looks like a bug, since Intent does have such method. Can you report it?
As a workaround, try moving most of the stuff to Java code, drop Java file in Unity project and call it.

Thanks for the info, Aurimas-Cernius.
I have absolutely no experience with Java, so that all went totally over my head.
Any chance you could break it down for a total noob?
:confused:

Export Android Studio project from Unity (checkbox in Build Settings window). Create new Java class in there with the launch code. The copy that .java file to Unity project and call into it the same way. The after building from Unity again you should get your java code called from Unity and can even debug .java code in Android Studio.