private boolean isAppInstalled(String packageName) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
Detect an app installed [duplicate]
문제
Could I know If there is a specific app installed in the phone programmatically? My app would make a process in one way or in other depending on that. How could I get this information?
Thanks!!
해결책
다른 팁
You must know the package name to check weather the application is installed or not
say if package name is like com.myapp.name
use the following to existence
boolean isExists;
try
{
getPackageManager().getPackageInfo("com.myapp.name", PackageManager.GET_ACTIVITIES);
isExists = true;
}
catch(NameNotFoundException e)
{
isExists = false;
// Sep 11, 2013 8:39:47 PM
Log.e("Exception", "NameNotFoundException" + String.valueOf(e.getMessage()));
e.printStackTrace();
}
Must use try catch around to handling expected error when NameNotFoundException is thrown
제휴하지 않습니다 StackOverflow