如何知道某个应用程序是否已成功安装在 android 中?我正在使用以下方法安装 apk 文件。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
如何知道某个应用程序是否已成功安装在 android 中?我正在使用以下方法安装 apk 文件。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
您可以查询已安装软件包的列表并查找您刚刚安装的软件包:
List pkgAppsList = context.getPackageManager().getInstalledPackages();
private boolean isAppInstalled(String uri) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
只需通过传递您需要检查的应用程序的包名称来调用该方法。
if(isAppInstalled("com.yourpackage.package")){
//app installed
}
else{
//app not installed
}