Last active
August 29, 2015 14:10
-
-
Save NLMartian/ef5a9b44902594aadb68 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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.teambition.today" > | |
<uses-permission android:name="android.permission.GET_TASKS" /> | |
</manifest> |
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 boolean isInForeground(Context context) { | |
ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); | |
ActivityManager.RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0); | |
String foregroundTaskPackageName = foregroundTaskInfo .topActivity.getPackageName(); | |
return context.getApplicationContext().getPackageName().equals(foregroundTaskPackageName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment