Search Unity

Intent to Open applications

Discussion in 'Android' started by heroichippo1, Dec 3, 2015.

  1. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    Hey Guys,

    I'm trying to open an Intent on Android and filter the possible intents by known package names like in the solution posted here.

    http://regis.decamps.info/blog/2011/06/intent-to-open-twitter-client-on-android/

    I am not very familiar with AndroidJavaClass and AndroidJavaObject usage, so far I can get the current activity, I can create an Intent and set the action and the type and even put the data i need into it. But i'm having trouble with the call to "packageManager.queryIntentActivities".

    I've tried something like this...
    Code (CSharp):
    1. AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    2. AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
    3. AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
    4. AndroidJavaObject newIntent = new AndroidJavaObject("android.content.Intent");
    5. newIntent.Call<AndroidJavaObject>("setType", "image/png");
    6. AndroidJavaObject list = packageManager.Call<AndroidJavaObject>("queryIntentActivities", newIntent, "android.intent.category.DEFAULT");
    but at run time i get an exception.

    AndroidJavaException: java.lang.NoSuchMethodError: no non-static method "Landroid/app/ApplicationPackageManager;.queryIntentActivities(Landroid.content.Intent;Ljava/lang/String;)Ljava/lang/Object;"
    java.lang.NoSuchMethodError: no non-static method "Landroid/app/ApplicationPackageManager;.queryIntentActivities(Landroid.content.Intent;Ljava/lang/String;)Ljava/lang/Object;"
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.a(Unknown Source)
    at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
    at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
    at UnityEngine.AndroidJNISafe.GetMethodID (IntPtr obj, System.String name, System.String sig) [0x00000] in <filename unknown>:0
    at UnityEngine._AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.String signature, Boolean isStatic) [0x00000] in <filename unknown>:0

    at UnityEngine.AndroidJNIHelper.GetMethodID (IntPtr javaClass, System.String methodName, Sy

    Also after i get the list i need to loop through the list and compare the results but I am not sure how to do that either.
    in the example java code he's using List<ResolveInfo> and I think i need to do something like this to get at the list items but i'm not sure if it will work because the error above happens before this can execute.
    AndroidJavaClass resolveInfoClass = new AndroidJavaClass("android.content.pm.ResolveInfo");
    AndroidJavaObject resolveInfoObject = list.Get<AndroidJavaObject>(resolveInfoClass.ToString());

    Any help would be appreciated.
     
  2. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
  3. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530