打开谷歌播放商店在移动版本的安卓链接

我有我的其他应用程序在我最新的应用程序的链接,我打开他们的方式。

Uri uri = Uri.parse("url");
Intent intent = new Intent (Intent.ACTION_VIEW, uri);
startActivity(intent);

这个代码打开浏览器版本的谷歌游戏商店。

当试图从我的手机打开,手机提示如果我想使用浏览器或谷歌播放,如果我选择第二个,它打开谷歌播放商店的移动版本。

你能告诉我这怎么可能同时发生吗?我的意思是不要问我,但直接打开手机版本的谷歌播放,我看到,而直接从电话打开它。

137053 次浏览

You'll want to use the specified market protocol:

final String appPackageName = "com.example"; // Can also use getPackageName(), as below
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));

Keep in mind, this will crash on any device that does not have the Market installed (the emulator, for example). Hence, I would suggest something like:

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}

While using getPackageName() from Context or subclass thereof for consistency (thanks @cprcrack!). You can find more on Market Intents here: link.

You can use Android Intents library for opening your application page at Google Play like that:

Intent intent = IntentUtils.openPlayStore(getApplicationContext());
startActivity(intent);

Below code may helps you for display application link of google play sore in mobile version.

For Application link :

Uri uri = Uri.parse("market://details?id=" + mContext.getPackageName());
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);


try {
startActivity(myAppLinkToMarket);


} catch (ActivityNotFoundException e) {


//the device hasn't installed Google Play
Toast.makeText(Setting.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();
}

For Developer link :

Uri uri = Uri.parse("market://search?q=pub:" + YourDeveloperName);
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);


try {


startActivity(myAppLinkToMarket);


} catch (ActivityNotFoundException e) {


//the device hasn't installed Google Play
Toast.makeText(Settings.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();


}

You can check if the Google Play Store app is installed and, if this is the case, you can use the "market://" protocol.

final String my_package_name = "........."  // <- HERE YOUR PACKAGE NAME!!
String url = "";


try {
//Check whether Google Play store is installed or not:
this.getPackageManager().getPackageInfo("com.android.vending", 0);


url = "market://details?id=" + my_package_name;
} catch ( final Exception e ) {
url = "https://play.google.com/store/apps/details?id=" + my_package_name;
}




//Open the app page in Google Play store:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);

Open app page on Google Play:

Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(intent);

In case, we want purpose to update by linking to the native google play store application :

val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(
"https://play.google.com/store/apps/details?id=com.example.android")
setPackage("com.android.vending")
}
startActivity(intent)

and if we want to open the instant app link here is the purpose kotlin code:

val uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
.buildUpon()
.appendQueryParameter("id", "com.example.android")
.appendQueryParameter("launch", "true")


// Optional parameters, such as referrer, are passed onto the launched
// instant app. You can retrieve these parameters using Activity.intent.data.
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId")


val intent = Intent(Intent.ACTION_VIEW).apply {
data = uriBuilder.build()
setPackage("com.android.vending")
}
startActivity(intent)

Please refer to Android Developer Link : https://developer.android.com/distribute/marketing-tools/linking-to-google-play#android-app