Unity打包出来的App 跳转其他 App

void Start()//在android测试成功
{
    bool fail = false;
    string bundleId = "跳转的包名";//包名称
    AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject ca = up.GetStatic("currentActivity");
    AndroidJavaObject packageManager = ca.Call("getPackageManager");
    AndroidJavaObject launchIntent = null;
    
    try
    {
        launchIntent = packageManager.Call("getLaunchIntentForPackage", bundleId);
        Debug.Log("没Try到");
    }
    catch (System.Exception e)
    {
        fail = true;    // 应用未安装
        Debug.LogError(e);
    }

    if (fail)
    {
        //跳转应用下载地址  测试过两次这里没用
        Application.OpenURL("网站下载链接");
        Debug.Log("跳转");
    }
    else
    {
        try
        {
            ca.Call("startActivity", launchIntent);
        }
        catch (System.Exception e)
        {
            Application.OpenURL("网站下载链接");//会跳转
            Debug.Log("捕获异常");
            throw e;
        }
    }
    up.Dispose();
    ca.Dispose();
    packageManager.Dispose();
    launchIntent.Dispose();
}

你可能感兴趣的:(Unity打包出来的App 跳转其他 App)