如何知道Android中是否已成功安装应用?我使用以下方法安装apk文件。
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
答案 0 :(得分:3)
您可以查询已安装软件包的列表并查找刚刚安装的软件包:
List pkgAppsList = context.getPackageManager().getInstalledPackages();
答案 1 :(得分:3)
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
}