Search Unity

opening discord app invite page from android game?

Discussion in 'Android' started by Tiny-Tree, Jun 9, 2019.

  1. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,275
    hello, i trying to open the discord app if installed directly from my game, it works on desktop build but can not get it to works on android build.
    here is what i did

    Code (CSharp):
    1.  
    2.             bool fail = false;
    3.             string bundleId = "com.discord";
    4.             AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    5.             AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
    6.             AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
    7.  
    8.             AndroidJavaObject launchIntent = null;
    9.             try
    10.             {
    11.                 launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
    12.                 launchIntent.Call<AndroidJavaObject>("putExtra", "invite-proxy", "he8en2");
    13. //none of these works => INVITE invite Invite server//Application.OpenURL("discord:///invite/he8en2");
    14.  
    15.             }
    16.             catch (System.Exception error)
    17.             {
    18.                 fail = true;
    19.             }
    20.  
    21.             if (fail)
    22.             {
    23.                 //open app in store
    24.                 Application.OpenURL(conf.GetLink("discord"));
    25.             }
    26.             else //open the app
    27.             {
    28.                 ca.Call("startActivity", launchIntent);
    29.             }