Android判断应用是否存在
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-02 05:57 点击:次
Android判断应用是否存在
文章分类:移动开发
通过包名判断
Java代码
public boolean checkBrowser(String packageName) {
if (packageName == null || "".equals(packageName))
return false;
try {
ApplicationInfo info = getPackageManager().getApplicationInfo(
packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
判断包中的Activity
Java代码
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", //$NON-NLS-1$
"com.android.settings.InstalledAppDetails"); //$NON-NLS-1$
intent.putExtra("com.android.settings.ApplicationPkgName", //$NON-NLS-1$
mCurrentPkgName);
List<ResolveInfo> acts = getPackageManager().queryIntentActivities(
intent, 0);
if (acts.size() > 0) {
startActivity(intent);
} else {
Toast.makeText(this,
getString(R.string.failed_to_resolve_activity),
Toast.LENGTH_SHORT).show();
}
通过包名判断
Java代码
public boolean checkBrowser(String packageName) {
if (packageName == null || "".equals(packageName))
return false;
try {
ApplicationInfo info = getPackageManager().getApplicationInfo(
packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
判断包中的Activity
Java代码
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", //$NON-NLS-1$
"com.android.settings.InstalledAppDetails"); //$NON-NLS-1$
intent.putExtra("com.android.settings.ApplicationPkgName", //$NON-NLS-1$
mCurrentPkgName);
List<ResolveInfo> acts = getPackageManager().queryIntentActivities(
intent, 0);
if (acts.size() > 0) {
startActivity(intent);
} else {
Toast.makeText(this,
getString(R.string.failed_to_resolve_activity),
Toast.LENGTH_SHORT).show();
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>