Created
August 13, 2015 12:13
-
-
Save Krishan14sharma/e580102e124a5c3767c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DetectHomeScreen { | |
| private static List<String> homePackageNamesCache; | |
| public static List<String> homePackageName(Context context){ | |
| Intent intent = new Intent(Intent.ACTION_MAIN); | |
| intent.addCategory(Intent.CATEGORY_HOME); | |
| List<ResolveInfo> info = context.getPackageManager().queryIntentActivities(intent, 0); | |
| List<String> homes = new ArrayList<String>(info.size()); | |
| for(int i=0; i<info.size(); i++){ | |
| homes.add(info.get(i).activityInfo.packageName); | |
| } | |
| homes.add(DetectHomeScreen.class.getPackage().getName()); | |
| return homes; | |
| } | |
| public static boolean isHomeRunning(Context context){ | |
| if (homePackageNamesCache==null) | |
| homePackageNamesCache = homePackageName(context); | |
| return isHomeRunning(context, homePackageNamesCache); | |
| } | |
| public static boolean isHomeRunning(Context context, List<String> homePackages){ | |
| ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |
| String topPackage = am.getRunningTasks(1).get(0).topActivity.getPackageName(); | |
| return homePackages.contains(topPackage); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment