开发者

How to know if an app has been installed successfully in android

开发者 https://www.devze.com 2023-02-24 07:06 出处:网络
How can I know if an app has been installed successfully in android? I am using the following method to install apk files.

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(fi开发者_JAVA百科le), "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
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消