Advertisement
Guest User

Check Android App in Foreground

a guest
Jul 21st, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1.     if (context.getPackageName().equalsIgnoreCase(((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0).topActivity.getPackageName())) {
  2.             Log.e("App", "App is in the foreground :-)");
  3.             return true;
  4.         } else {
  5.             Log.e("App", "App is NOT in the foreground :-( ");
  6.             return false;
  7.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement