如何知道一个应用程序是否已在android中成功安装 [英] How to know if an app has been installed successfully in android

查看:35
本文介绍了如何知道一个应用程序是否已在android中成功安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道一个应用程序是否已在 android 中成功安装?我使用以下方法安装apk文件.

How can I know if an app has been installed successfully in android? I am using the following method to install apk files.

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);

推荐答案

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;
}

只需传递您需要检查的应用程序的包名即可调用该方法.

Just call the method by passing the package name of the application you need to check.

if(isAppInstalled("com.yourpackage.package")){
//app installed
}
else{
//app not installed
}

这篇关于如何知道一个应用程序是否已在android中成功安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆