打开另一个应用程序并传入URL

当我点击按钮时,我正在尝试团结打开Goog​​le+应用。 我在我的Android设备上运行应用程序,但它不起作用这是我使用的代码

Application.OpenURL ("gplus://plus.google.com/+JewelMash"); 

此代码有效,但它会提示您选择使用浏览器或Google +应用程序打开它

 Application.OpenURL ("https://plus.google.com/+JewelMash"); 

Application.OpenURL函数无法执行此操作。 我以前做过这个并且愿意分享。 您可以创建一个Java插件来执行此操作,也可以使用AndroidJavaClass和C#来执行此操作。 我在C#中做了我的,因为这是一个简单的插件。

打开任何应用程序:

 public bool openUrl(string packageName) { #if UNITY_ANDROID AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject unityActivity = unityPlayer.GetStatic("currentActivity"); AndroidJavaObject pManager = unityActivity.Call("getPackageManager"); AndroidJavaObject intent = null; try { intent = pManager.Call("getLaunchIntentForPackage", packageName); unityActivity.Call("startActivity", intent); return true; } catch (Exception e) { Debug.LogWarning("Failed to Opeen App: " + e.Message); //Open with Browser string link = "https://play.google.com/store/apps/details?id=" + packageName + "&hl=en"; Application.OpenURL(link); return false; } #endif return false; } 

用法

 bool success = openUrl("com.google.android.apps.plus"); 

要打开另一个应用程序,然后传入Url:

 public bool openUrl(string packageName, string url) { #if UNITY_ANDROID AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject unityActivity = unityPlayer.GetStatic("currentActivity"); AndroidJavaObject pManager = unityActivity.Call("getPackageManager"); //For accessing static strings(ACTION_VIEW) from android.content.Intent AndroidJavaClass intentStaticClass = new AndroidJavaClass("android.content.Intent"); string actionView = intentStaticClass.GetStatic("ACTION_VIEW"); //Create Uri AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); AndroidJavaObject uriObject = uriClass.CallStatic("parse", url); //Psss ACTION_VIEW and Uri.parse to the intent AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", actionView, uriObject); try { if (pManager.Call("getPackageInfo", packageName, 0) != null) { intent.Call("setPackage", packageName); } } catch (Exception e) { Debug.LogWarning("Failed to Open App 1: " + e.Message); return false; } try { unityActivity.Call("startActivity", intent); return true; } catch (Exception e) { Debug.LogWarning("Failed to Open App 2: " + e.Message); //Open with Browser string link = "https://play.google.com/store/apps/details?id=" + packageName + "&hl=en"; Application.OpenURL(link); return false; } #endif return false; } 

用法

  bool success = openUrl("com.google.android.apps.plus", "https://plus.google.com/+JewelMash"); 

您正在寻找第二个代码。 如果要查找其他应用程序的包名,请使用下图:

在此处输入图像描述

此解决方案适用于Android。 您需要Object-C插件才能在iOS中执行此操作。 我建议你在iOS上提出一个关于如何做到这一点的新问题。