Android App Play 商店重定向

标签 android android-intent android-manifest

我写了一段代码来列出所有已安装的应用程序。我有一个按钮事件,它将被重定向到 Google 商店中特定的应用程序主页。但是我无法成功重定向它们。这是我使用的代码。我没有在 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())));
    }
}

提前致谢

最佳答案

要打开 Native 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)));
        }
    } 

关于Android App Play 商店重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33118724/

相关文章:

android - 布局问题状态栏

android - 选择图像时应用程序崩溃

android - 在 v23 上找不到 Symbol Manifest.permission.WRITE_EXTERNAL_STORAGE

android - CATEGORY_INFO 在 Android 中有什么用?

android - 设备上应用程序图标下缺少应用程序标题

java - 根据 maven android 构建配置文件更新应用程序名称和 Logo

android - FB Android-SDK : How to wait until callback of request is completed

java - Android 包管理器列表不显示导航图标

android - 在 Kotlin 中使用 okhttp 信任 HTTPS 证书时出错

android - 如何在 onNewIntent() 中捕获新的 Intent?