android 如何知道应用程序是否安装成功

发布于 2024-10-31 16:33:42 字数 257 浏览 1 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤星 2024-11-07 16:33:42
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
}
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
}
恬淡成诗 2024-11-07 16:33:42

您可以查询已安装的软件包列表并查找刚刚安装的软件包:

List pkgAppsList = context.getPackageManager().getInstalledPackages();

http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledPackages%28int%29

You can query the list of installed packages and look for the one you just installed:

List pkgAppsList = context.getPackageManager().getInstalledPackages();

http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledPackages%28int%29

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文