Created
July 9, 2015 06:06
-
-
Save myaaaaa-chan/4cc573e077ca6a886a73 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
| private static boolean isAppOnForeground(Context context) { | |
| ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |
| List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); | |
| if (appProcesses == null) { | |
| return false; | |
| } | |
| final String packageName = context.getPackageName(); | |
| for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { | |
| if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment