我可以知道手机中是否以编程方式安装了特定的应用程序吗?我的应用程序会以一种方式或另一种方式进行流程,具体取决于该流程。我怎么能得到这些信息?
谢谢!!
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;
}
您必须知道软件包名称才能检查应用程序是否安装
说如果包名像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 来处理预期的错误