在手机版android中打开google play store的链接

我有我的最新应用程序中的其他应用程序的链接,我以这种方式打开它们。

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

此代码打开谷歌Play商店的浏览器版本。

当试图从我的手机打开,手机会提示是否要使用浏览器或谷歌播放,如果我select第二个,它会打开手机版的谷歌播放存储。

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

您将要使用指定的market协议:

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

请记住,这将在没有安装市场的任何设备(例如仿真器)上崩溃。 因此,我会build议像这样的:

 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))); } 

Context或其子类使用getPackageName()来保持一致性(谢谢@cprcrack !)。 您可以在这里find更多关于市场意图的链接链接

下面的代码可以帮助你在移动版本中显示google play sore的应用程序链接。

对于Application链接:

 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(); } 

对于开发者链接:

 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(); } 

您可以使用Android Intents库在Google Play上打开您的应用程序页面:

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

d.android.com上的文档:http://developer.android.com/distribute/googleplay/promote/linking.html

您可以检查是否安装了Google Play商店应用,如果是这种情况,则可以使用“market://”协议。

 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); 

在Google Play上打开应用页面:

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