0

如何检查是否使用 getPackageManager 安装了应用程序?我不知道。谢谢。安卓。

    Intent intent = new Intent();
    intent.setClassName("PACKAGE_NAME", "PACKAGE_NAME.TARGET_ACTIVITY");
    if (isCallable(context, intent)) {
        // Attach any extras, start or start with callback
    } else {
        // Respond to the application or activity not being available
    }
4

4 回答 4

0

尝试这个 :

private boolean appInstalledorNot(String packageName) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
    pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
    app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
    app_installed = false;
}
return app_installed;
}
于 2013-09-12T17:56:41.190 回答
0

您可以使用以下代码段获取已安装应用程序的列表

PackageManager packageManager = getPackageManager();
  List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)

现在您可以获取每个已安装应用程序的包名,然后可以检查包名

ApplicationInfo data = appsList.get(position);
String packageName = data.packageName;

查看另一个示例如何获取 Android 中已安装应用程序的列表

于 2013-09-12T17:52:10.090 回答
0

我认为queryIntentActivities更合适,因为您的意图中定义了目标活动。如果列表返回是.size() == 0. 然后可以肯定地说它不可用。

protected boolean isCallable(Context context, Intent intent) {
    List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
    return activities.size() > 0 ? true : false;
}
于 2013-09-12T17:53:52.237 回答
0
protected boolean isAppInstalled(String packageName) {
        Intent mIntent = getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);
        if (mIntent != null) {
            return true;
        }
        else {
            return false;
        }
    }
于 2013-09-12T17:50:51.070 回答