Search Unity

Android: Calling Google Play Activity From Unity

Discussion in 'Scripting' started by dis-s, Apr 15, 2019.

  1. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    48
    Hello!

    I need to implement in Unity the following Java code:

    Code (CSharp):
    1. currentActivity.startActivity(
    2.         new Intent(Intent.ACTION_VIEW, Uri.parse(appUrl))
    3.                 .setPackage("com.android.vending"));
    This code is perfectly works in Android Studio.

    I tried to inplement it in Unity and this is not working:

    Code (CSharp):
    1. public void OpenGooglePlay()
    2. {
    3.     string appUrl = "https://play.google.com/store/apps/details?id=net.cleverbit.DinoPuzzles";
    4.  
    5.     Log("OpenGooglePlay() " + appUrl);
    6.  
    7.     try
    8.     {
    9.         // Java:
    10.         // activity.startActivity(
    11.         //     new Intent(Intent.ACTION_VIEW, Uri.parse(appUrl))
    12.         //         .setPackage("com.android.vending"));
    13.         //
    14.         using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    15.         using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
    16.         using (var uriClass = new AndroidJavaClass("android.net.Uri"))
    17.         using (var uri = uriClass.CallStatic<AndroidJavaObject>("parse", appUrl))
    18.         using (var googlePlayIntent = new AndroidJavaObject("android.intent.action.VIEW", uri))
    19.         using (googlePlayIntent.Call<AndroidJavaObject>("setPackage", "com.android.vending" /* Play Store */))
    20.         {
    21.             activity.Call("startActivity", googlePlayIntent);
    22.         }
    23.     }
    24.     catch (System.Exception e)
    25.     {
    26.         Log("Exception: " + e.Message);
    27.     }
    28. }

    "Java.lang.ClassNotFoundException: android.intent.action.VIEW" raised on Android device.

    What do I do wrong? I'd really appreciate for help.
     
  2. spothieux

    spothieux

    Joined:
    Sep 20, 2015
    Posts:
    9
    Hi, did you find the solution to your problem.
    I have the same issue in my project.

    Thanks
     
  3. ShoaibAslamTintash

    ShoaibAslamTintash

    Joined:
    Sep 6, 2018
    Posts:
    11
    "Java.lang.ClassNotFoundException: android.intent.action.VIEW" raised on Android device.

    I have the same issue in my project . Did anything worked for you guys?