Hello!
I need to implement in Unity the following Java code:
currentActivity.startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(appUrl))
.setPackage("com.android.vending"));
This code is perfectly works in Android Studio.
I tried to inplement it in Unity and this is not working:
public void OpenGooglePlay()
{
string appUrl = "https://play.google.com/store/apps/details?id=net.cleverbit.DinoPuzzles";
Log("OpenGooglePlay() " + appUrl);
try
{
// Java:
// activity.startActivity(
// new Intent(Intent.ACTION_VIEW, Uri.parse(appUrl))
// .setPackage("com.android.vending"));
//
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
using (var uriClass = new AndroidJavaClass("android.net.Uri"))
using (var uri = uriClass.CallStatic<AndroidJavaObject>("parse", appUrl))
using (var googlePlayIntent = new AndroidJavaObject("android.intent.action.VIEW", uri))
using (googlePlayIntent.Call<AndroidJavaObject>("setPackage", "com.android.vending" /* Play Store */))
{
activity.Call("startActivity", googlePlayIntent);
}
}
catch (System.Exception e)
{
Log("Exception: " + e.Message);
}
}
“Java.lang.ClassNotFoundException: android.intent.action.VIEW” raised on Android device.
What do I do wrong? I’d really appreciate for help.