Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Problem with AndroidJavaObject - java.lang.NoSuchMethodError

Discussion in 'Android' started by DanTaylor, Feb 24, 2021.

  1. DanTaylor

    DanTaylor

    Joined:
    Jul 6, 2013
    Posts:
    119
    Hi there.
    I am trying to call some Java code to open a browser window on Oculus Quest.
    Here is my script...
    Code (CSharp):
    1. var intent = new AndroidJavaObject("android.content.Intent", "com.oculus.vrshell.intent.action.LAUNCH");
    2.  
    3. intent.Call("setPackage", "com.oculus.vrshell");
    4. intent.Call("putExtra", "uri", "ovrweb://webtask?uri=" + url);
    5. intent.Call("putExtra", "intent_data", new AndroidJavaClass("android.net.Uri").CallStatic<AndroidJavaObject>("parse", "systemux://browser"));
    6.  
    7. 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
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    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.
     
  3. DanTaylor

    DanTaylor

    Joined:
    Jul 6, 2013
    Posts:
    119
    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?
    :/
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    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.