Created
January 20, 2017 17:31
-
-
Save escamoteur/e327a839820eb8fa609f3bfafd3624b2 to your computer and use it in GitHub Desktop.
This file contains 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 bool IsAppInBackground(Context context) | |
{ | |
var isInBackground = true; | |
var am = (ActivityManager) context.GetSystemService(Context.ActivityService); | |
if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch) | |
{ | |
var runningProcesses = | |
new List<ActivityManager.RunningAppProcessInfo>(am.RunningAppProcesses); | |
foreach (var processInfo in runningProcesses) | |
{ | |
if (processInfo.Importance == Importance.Foreground) | |
{ | |
foreach (var s in processInfo.PkgList) | |
{ | |
if (s.Equals(context.PackageName)) | |
{ | |
isInBackground = false; | |
} | |
} | |
} | |
} | |
} | |
return isInBackground; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment