android 在移动的版安卓中打开Google Play商店的链接

bmvo0sr5  于 2022-12-28  发布在  Android
关注(0)|答案(6)|浏览(296)

我在最新的应用程序中有其他应用程序的链接,我就这样打开它们。

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

此代码打开Google Play商店的浏览器版本。
当试图从我的手机打开时,手机会提示我是想使用浏览器还是Google Play,如果我选择第二个,它会打开移动的版Google Play商店。
你能告诉我这是怎么发生的吗?我的意思是不问我,而是直接打开移动的版的Google Play,我看到的,而打开它直接从手机。

xqnpmsa8

xqnpmsa81#

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

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

请记住,这将在任何没有安装Market的设备上崩溃(例如模拟器)。因此,我建议如下:

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!)。您可以在此处找到更多关于市场意图的信息:链接

twh00eeo

twh00eeo2#

下面的代码可以帮助您在移动的版Google Play疮显示应用程序链接。
对于应用程序链接:

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

            }
jei2mxaa

jei2mxaa3#

您可以使用Android Intents库在Google Play中打开应用页面,如下所示:

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

ajsxfq5m4#

您可以检查是否安装了 *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);
mzaanser

mzaanser5#

在Google Play上打开应用页面:

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

0tdrvxhp6#

在这种情况下,我们希望通过链接到本地Google Play商店应用程序来更新目的:

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)

如果我们想打开即时应用程序链接这里是目的Kotlin代码:

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)

请参阅Android开发人员链接:https://developer.android.com/distribute/marketing-tools/linking-to-google-play#android-app

相关问题