Google Play link in GAME

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 ?

In Java (Do not confuse with UnityScript). Add it in a method, call it via JNI from Unity

// Opens a certain app in Google play
Intent intent = new Intent(Intent.ACTION_VIEW, "market://details?q=pname:com.mycopmany.myapp");
startActivity(intent);

// or search for a term
Intent intent = new Intent(Intent.ACTION_VIEW, "market://search?q=some+search+query");
startActivity(intent);
1 Like

I make like this and work perfect :slight_smile: but thanks Tsenq

function Start () {
    Application.OpenURL ("market://details?q=pname:com.mycopmany.myapp/");
}
2 Likes

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.

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!

PackageManager pm = getPackageManager();

// create an empty http request
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); //in your case the Uri should be  http://play.google.com/store/....

String appName;
try {
	// get all activities which can perform this intent
	List<ResolveInfo> resolveInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

	// reserve memory 
	int size = resolveInfo.size();

	ArrayList<String> entries = new ArrayList<String>(size-1);
	ArrayList<String> entryValues = new ArrayList<String>(size-1);
	
	ResolveInfo ri;
	for(int i=0;i<size;i++) {
		// loop through all activities
		ri = resolveInfo.get(i);

		// exclude the own app
		if(!ri.activityInfo.packageName.equalsIgnoreCase("com.company.appname")) {
			appName = pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString();
			
			entryValues.add(ri.activityInfo.packageName+"/"+ri.activityInfo.name);
			entries.add(appName);
		}
	}
}

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

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://")); //in your case the Uri should be  http://play.google.com/store/....

// That's the two values you get from ri.activityInfo.name and ri.activityInfo.packageName
ComponentName compName = new ComponentName(compPackage, compCls); 

// set the component to the intent
intent.setComponent(compName);

// send the intent
startActivity(intent);

This will send the Intent directly to the chosen Activity, without showing the Dialog.

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.

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.

You can also use this:

http://stackoverflow.com/questions/10342327/does-samsung-apps-support-a-uri-scheme-to-redirect-to-specific-apps

You can use those C# code :

AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "market://details?id=...");

AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject(
                "android.content.Intent",
                intentClass.GetStatic<string>("ACTION_VIEW"),
                uriObject
);

AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");

currentActivity.Call("startActivity", intentObject);
6 Likes

Thanks friend! Works for me.

Thanks !

1 Like