【问题标题】:Android App Play Store RedirectionAndroid App Play 商店重定向
【发布时间】:2015-10-14 07:04:33
【问题描述】:

我编写了一个代码来列出所有已安装的应用程序。我有一个按钮事件,它将被重定向到 Google 商店中的特定 App 主页。但是我无法成功重定向它们。这是我使用的代码。我没有在 uri 中获取应用程序的包名称,因此我得到 “在服务器上找不到 URL”。请提出您的宝贵建议。

public void update(View view) {
    Context context = this;
    Uri uri = Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    // To count with Play market backstack, After pressing back button,
    // to taken back to our application, we need to add following flags to intent.
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
    }
}

提前致谢

【问题讨论】:

  • 你使用的是自己app的pkg名context = this; context.getPackageName()你需要使用其他app的包名
  • 您好,感谢您的建议。如何动态设置上下文以重定向到其他应用程序的包名
  • 我认为this 是您所需要的。不是上下文。

标签: android android-intent android-manifest


【解决方案1】:

要打开原生 Play 商店页面,您必须使用此 Play 商店架构

market://details?id=your.app.package.name

但请记住,设备可能没有 Google Play 服务或 Play 商店本身。

所以为了避免崩溃,捕获异常并尝试打开正常的URL

public static void openPlayStorePage(Activity parentActivity, String targetPackageName) {

        try {
            parentActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + targetPackageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            parentActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + targetPackageName)));
        }
    } 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 2015-07-21
    • 1970-01-01
    相关资源
    最近更新 更多