如果没有下载,Java android检查是否安装了Acrobat Reader

时间:2017-03-28 09:15:12

标签: java android

我想在未安装时检查是否安装了Acrobat Reader我想在Adobe Acrobat Reader上打开Android市场

这是我检查的方式:

public static boolean canDisplayPdf(Context context) 
{
    PackageManager packageManager = context.getPackageManager();
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    testIntent.setType(MIME_TYPE_PDF);
    if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
        return true;
    } else {
        return false;
    }
}

接下来我这个方法返回false时我想打开一个andrid market(apk):

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try
{
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=Adoba Acrobat Reader" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) 
{
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id= Adoba Acrobat Reader" + appPackageName)));
}

但是打开一个它做得好的Android市场

2 个答案:

答案 0 :(得分:2)

您可以使用此方法检查Adobe Acrobat Reader是否已安装:

private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
try {
    packageManager.getPackageInfo(packagename, 0);
    return true;
} catch (NameNotFoundException e) {
    return false;
}
}

用法:

boolean isAdobeInstalled = isPackageInstalled("com.adobe.reader", getPackageManager());
if (isAdobeInstalled) {
   startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.adobe.reader")));
}

答案 1 :(得分:0)

更改

Uri.parse("http://play.google.com/store/apps/details?id= Adoba Acrobat Reader" + appPackageName)));

Uri.parse("https://play.google.com/store/apps/details?id=com.adobe.reader)));