Android判断应用是否存在 ,Android 关闭整个应用程序
来源:互联网 发布:淘宝客服下载 编辑:程序博客网 时间:2024/05/22 15:47
通过包名判断
publicboolean 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
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();
}
Android 关闭整个应用程序
当应用不再使用时,通常需要关闭应用,可以使用以下方法关闭android应用:
第一种方法:首先获取当前进程的id,然后杀死该进程。
android.os.Process.killProcess(android.os.Process.myPid())
第二种方法:终止当前正在运行的Java虚拟机,导致程序终止
System.exit(0);
第三种方法:强制关闭与该包有关联的一切执行
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
manager.restartPackage(getPackageName());
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
- Android判断应用是否存在 ,Android 关闭整个应用程序
- Android判断应用是否存在 及 Android 关闭整个应用程序
- Android判断应用是否存在 ,Android 关闭整个应用程序
- Android判断应用是否存在
- Android判断应用是否存在
- android关闭整个应用程序
- Android 关闭整个应用程序
- Android 关闭整个应用程序
- Android判断应用或Activity是否存在
- Android判断应用或Activity是否存在
- Android判断应用或Activity是否存在
- Android判断应用或Activity是否存在
- Android判断应用或Activity是否存在
- Android应用程序快捷方式操作(添加,删除,判断是否存在)
- android退出时关闭整个应用程序
- android判断是否存在网络
- android判断程序是否存在
- android判断文件是否存在
- 怕晒黑 夏天警惕吃这些食物
- LinkedHashMap 根据PUT顺序排序Map
- 【JS--Jquery】--append() 和appendTo()用法
- Web开发中http请求的url的拼写
- PHP中字符串截断函数mb_strimwidth、mb_substr、mb_strcut区别
- Android判断应用是否存在 ,Android 关闭整个应用程序
- 获取android中正在运行应用程序的列表
- 【struts2】开发过程中遇到的需要注意的小问题的原因与解决方法
- 多媒体技术基础及应用
- mysql登陆不了
- 使用GridViewRow加入checkbox进行多行删除
- 时间空间
- tar使用
- poj 1008 Maya Calendar