Search Unity

[ANDROID] How can this intent be made in Unity?

Discussion in 'Editor & General Support' started by molul, Dec 18, 2017.

  1. molul

    molul

    Joined:
    Jan 21, 2017
    Posts:
    15
    Hi! I'm trying to launch an emulator from my frontend made in Unity. I tried with Retroarch, and while I could launch it, I couldn't make it detect parameters like the rom path (I get no error messages, just that Retroarch seems to ignore it), so I moved to another emulator: MD.emu.

    Now I'm having a similar issue. I saw this intent code example for this emulator:

    Code (CSharp):
    1.     public Intent getEmulatorIntent(String fileName, String ime, Context context) {
    2.             Intent intent = new Intent();
    3.             intent.setComponent(new ComponentName("com.explusalpha.MdEmu", "com.imagine.BaseActivity"));
    4.             intent.setAction("android.intent.action.VIEW");
    5.             intent.setData(Uri.fromFile(new File(fileName)));
    6.             return intent;
    7.         }
    8.  
    And also this adb command:
    Code (CSharp):
    1. start -n com.explusalpha.MdEmu/com.imagine.BaseActivity -a android.intent.action.VIEW -eu Uri "file://%rom%"
    Now, I've tried some Unity intent examples I've found, and this is how far I got:

    Code (CSharp):
    1.     bool fail = false;
    2.  
    3.     string bundleId = "com.explusalpha.MdEmu";
    4.     string romPath = currentGame.romPath;
    5.     AndroidJavaClass unityPlayerClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
    6.     AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject> ("currentActivity");
    7.     AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");
    8.     AndroidJavaObject intent = null;
    9.  
    10.     try {
    11.         intent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
    12.         AndroidJavaClass uriClass = new AndroidJavaClass ("android.net.Uri");
    13.         AndroidJavaObject uri = uriClass.CallStatic<AndroidJavaObject> ("parse", romPath);
    14.         intent.Call ("setData", uri);
    15.     }
    16.     catch (System.Exception e) {
    17.         fail = true;
    18.         Debug.Log ("ERROR: " + e.ToString ());
    19.     }
    20.  
    21.     if (!fail) {
    22.         currentActivity.Call ("startActivity", intent);
    23.     }
    24.  
    25.     unityPlayerClass.Dispose();
    26.     currentActivity.Dispose();
    27.     packageManager.Dispose();
    28.     intent.Dispose();
    29.  
    With this code I get an error on the line "intent.Call ("setData", uri);", saying that such method doesn't exist.
    Could anybody give me some hint about adapting that (apparently working) Java code to Unity, please? Well, the only pending thing is the "setData" for setting the rom path.

    I'm not sure about the "-eu" parameter in the adb command. I think -e is for "putExtra", but I can't find what "-eu" would be.
     
  2. developer_metronome

    developer_metronome

    Joined:
    Dec 28, 2023
    Posts:
    2
    Hey were you ever able to solve it? I am getting this error too
    Code (CSharp):
    1. java.lang.NoSuchMethodError: no non-static method with name='setData' signature='(Ljava/lang/String;)Ljava/lang/Object;' in class Ljava.lang.Object;
     
    Last edited: Dec 28, 2023