gpt4 book ai didi

android - 如何知道一个应用程序是否已在android中安装成功

转载 作者:太空狗 更新时间:2023-10-29 16:24:29 24 4
gpt4 key购买 nike

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

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

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

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

关于android - 如何知道一个应用程序是否已在android中安装成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5620112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com