Android系统判断当前界面是否是桌面Launcher
public static boolean isHome(Context context) {
ActivityManagerm ActivityManager =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);
return getHomes(context).contains(rti.get(0).topActivity.getPackageName());
}
/**
*获得属于桌面的应用的应用包名称
*
* @return返回包含所有包名的字符串列表
*/
public staticList getHomes(Context context) {
List<String> names = new ArrayList<String>();
PackageManagerpackageManager = context.getPackageManager();
Intent intent = newIntent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> resolveInfos =packageManager.queryIntentActivities(intent,
PackageManager.GET_INTENT_FILTERS);
for (ResolveInforesolveInfo : resolveInfos) {
names.add(resolveInfo.activityInfo.packageName);
}
return names;
}
网友评论