【问题标题】:How to open 'Amazon' app on playstore programmatically?如何以编程方式在 Playstore 上打开“亚马逊”应用程序?
【发布时间】:2017-09-07 00:55:29
【问题描述】:

我正在尝试以编程方式打开亚马逊应用程序,如果在手机中找不到它,则会要求用户从 Play 商店安装它,但问题是当我尝试在 Playstore 中打开它时,它是显示Item not found 错误。

这是我的代码:

public void openApp(final String packageName, final String appName) {
        Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(packageName);
         if (intent != null) {
             startActivity(intent);
         } else {
             AlertDialog.Builder builder;
             builder = new AlertDialog.Builder(MainActivity.this);
             builder.setMessage(appName + " not found. Would you like to install " + appName + " from play store?")
                     .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int which) {
                             try {
                                 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
                             } catch (android.content.ActivityNotFoundException anfe) {
                                 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
                             }
                         }
                     })
                     .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int which) {

                         }
                     })
                     .show();
         }
    }

其中packageNamein.amazon.mShop.android.shoppingappNameAmazon

我从应用的 playstore 链接中获得了包名称,即https://play.google.com/store/apps/details?id=in.amazon.mShop.android.shopping&hl=en

这里出了什么问题,如果在设备中找不到,我如何才能在 Playstore 上成功打开亚马逊应用?

【问题讨论】:

  • 我刚刚检查了您的代码,它在 Play 商店中加载亚马逊应用对我来说很好。您确定您传递的包名称与您在此处发布的相同吗?即 in.amazon.mShop.android.shopping?。请确保那里没有错字。
  • @sam_0829 我又犯了一个愚蠢的错误。谢谢!

标签: android android-intent android-package-managers


【解决方案1】:
 private boolean appInstalledOrNot(String uri) {
        PackageManager pm = getPackageManager();
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
        }

        return false;
    }

使用此方法查找应用是否安装然后

boolean isAppInstalled = appInstalledOrNot("com.check.application");

    if(isAppInstalled) {
        //This intent will help you to launch if the package is already installed
        Intent LaunchIntent = getPackageManager()
            .getLaunchIntentForPackage("com.check.application");
        startActivity(LaunchIntent);

        Log.i("Application is already installed.");       
    } else {
        // Do whatever we want to do if application not installed
        // For example, Redirect to play store

        Log.i("Application is not currently installed.");
    }

【讨论】:

    猜你喜欢
    • 2019-03-16
    • 1970-01-01
    • 2011-10-07
    • 2011-10-16
    • 1970-01-01
    • 2018-12-02
    • 2017-11-30
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多