ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
Log.e("PhoneWindowManager", "the foreground activity is : " + componentInfo.getPackageName());
记得添加如下权限:
<uses-permission android:name="android.permission.GET_TASKS"/>