Search Unity

Google Play link in GAME

Discussion in 'Android' started by alek12, Jun 23, 2012.

  1. alek12

    alek12

    Joined:
    Mar 24, 2012
    Posts:
    7
    Hi guys i want create a button which one have link to google play and when user press it then it will open google play and find a game. Is any way to do that ?
     
  2. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    In Java (Do not confuse with UnityScript). Add it in a method, call it via JNI from Unity

    Code (csharp):
    1.  
    2. // Opens a certain app in Google play
    3. Intent intent = new Intent(Intent.ACTION_VIEW, "market://details?q=pname:com.mycopmany.myapp");
    4. startActivity(intent);
    5.  
    6. // or search for a term
    7. Intent intent = new Intent(Intent.ACTION_VIEW, "market://search?q=some+search+query");
    8. startActivity(intent);
    9.  
     
    myworkema likes this.
  3. alek12

    alek12

    Joined:
    Mar 24, 2012
    Posts:
    7
    I make like this and work perfect :) but thanks Tsenq

    Code (csharp):
    1. function Start () {
    2.     Application.OpenURL ("market://details?q=pname:com.mycopmany.myapp/");
    3. }
     
    jovalent and Oxygeniium like this.
  4. raviraj_vdy

    raviraj_vdy

    Joined:
    May 14, 2009
    Posts:
    309
    Hello Guys,

    I am using the same method that u have mentioned to open my games URL from with in the applications it works perfect but my problem is that when ever I hits the URL it displays an options to me wether I want to open it in the mobiles browser or in the play applications, What I want is it should not ask this options and insted directly open it in the Play applications is this possible.

    Thanks,
    Raviraj.
     
    Last edited: Aug 24, 2012
  5. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    This is because you have two Apps who registered for the same scheme (http:// and/or https://) and the same authority (play.google.store / market.android.com). When more than 1 App can handle an Intent, the user will always be requested, this is intentional to allow the user to open it in the App of his choice.

    The user can enable the Check mark to make an application his favorite.

    There are ways to send an Intent directly to a single Application, but this method is highly discouraged, because that App may or may not exist on the users device. For example, there are devices without Google Play (i.e. Kindle, Nook who use non-standard Android Devices who don't implement all the features to comply with Google Play license services).

    I used this code in my "Long Url Expander" App to get a list of all available Apps to populate a Pulldown menu with it.

    //Java code!
    Code (csharp):
    1.  
    2. PackageManager pm = getPackageManager();
    3.  
    4. // create an empty http request
    5. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); //in your case the Uri should be  http://play.google.com/store/....
    6.  
    7. String appName;
    8. try {
    9.     // get all activities which can perform this intent
    10.     List<ResolveInfo> resolveInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    11.  
    12.     // reserve memory
    13.     int size = resolveInfo.size();
    14.  
    15.     ArrayList<String> entries = new ArrayList<String>(size-1);
    16.     ArrayList<String> entryValues = new ArrayList<String>(size-1);
    17.    
    18.     ResolveInfo ri;
    19.     for(int i=0;i<size;i++) {
    20.         // loop through all activities
    21.         ri = resolveInfo.get(i);
    22.  
    23.         // exclude the own app
    24.         if(!ri.activityInfo.packageName.equalsIgnoreCase("com.company.appname")) {
    25.             appName = pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString();
    26.            
    27.             entryValues.add(ri.activityInfo.packageName+"/"+ri.activityInfo.name);
    28.             entries.add(appName);
    29.         }
    30.     }
    31. }
    32.  
    This will return a list of all Apps who can (and want) to handle that app. You could then select one (i.e. check if Google Play exist and use it, if Google Play doesn't exist, use Amazon Store, if that doesn't exist look for Nook etc.). Next step is to create a component object

    Code (csharp):
    1.  
    2. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); //in your case the Uri should be  http://play.google.com/store/....
    3.  
    4. // That's the two values you get from ri.activityInfo.name and ri.activityInfo.packageName
    5. ComponentName compName = new ComponentName(compPackage, compCls);
    6.  
    7. // set the component to the intent
    8. intent.setComponent(compName);
    9.  
    10. // send the intent
    11. startActivity(intent);
    12.  
    This will send the Intent directly to the chosen Activity, without showing the Dialog.
     
  6. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    219
    I tried it and works perfect with Google Play, but with Samsung Apps it open the Web browser instead of Samsung Apps.

    it don´t work with Samsung Apps?.

    Regards.
     
  7. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    219
    Solved.

    Send your app link from Samsung Galaxy Apps to your email, and use this link instead of the web link from your PC browser.
     
  8. www_3dart_es

    www_3dart_es

    Joined:
    May 24, 2013
    Posts:
    219
  9. BananaGrp

    BananaGrp

    Joined:
    Dec 24, 2015
    Posts:
    1
    You can use those C# code :
    Code (CSharp):
    1. AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
    2. AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "market://details?id=...");
    3.  
    4. AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
    5. AndroidJavaObject intentObject = new AndroidJavaObject(
    6.                 "android.content.Intent",
    7.                 intentClass.GetStatic<string>("ACTION_VIEW"),
    8.                 uriObject
    9. );
    10.  
    11. AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    12. AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
    13.  
    14. currentActivity.Call("startActivity", intentObject);
     
  10. allanppss

    allanppss

    Joined:
    Nov 16, 2017
    Posts:
    1
    Thanks friend! Works for me.
     
  11. ShoaibAslamTintash

    ShoaibAslamTintash

    Joined:
    Sep 6, 2018
    Posts:
    11
    Thanks !
     
    shakir1311 likes this.