lockAppName 是須要判斷Activity的全稱(包括包名).spa
private boolean getTopApp(Context mContext) { String lockAppName = "com.celltick.lockscreen.LockerActivity"; String topActivityName = ""; ActivityManager am = (ActivityManager) mContext .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTasks = am .getRunningTasks(1); if (runningTasks != null && !runningTasks.isEmpty()) { ActivityManager.RunningTaskInfo taskInfo = runningTasks.get(0); topActivityName = taskInfo.topActivity.getClassName(); } if (lockAppName.equals(topActivityName)) { return true; } return false; }