我可以知道如果手机中以编程方式安装了特定的应用程序吗?我的应用程序会以某种方式或其他方式进行处理。我怎么能得到这些信息?
谢谢!
答案 0 :(得分:5)
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;
}
答案 1 :(得分:1)
必须知道软件包名称才能检查应用程序的安装天气
如果包名称类似于 com.myapp.name
使用以下内容
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();
}
当抛出 NameNotFoundException 时,必须使用try catch来处理预期的错误