Exemple #1
0
        public void run() {

          Logger.getLogger().d("block service is running...");

          mBlockList = BlockUtils.getBlockList(getApplicationContext());

          String packageName;

          if (Build.VERSION.SDK_INT >= 21) {
            List<ActivityManager.AppTask> appTasks = getAppTasks();
            ActivityManager.AppTask appTask = appTasks.get(0);

            packageName = appTask.getTaskInfo().baseIntent.getComponent().getPackageName();
          } else {

            ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
            packageName = topActivity.getPackageName();
          }

          if (mBlockList != null && mBlockList.contains(packageName)) {
            Intent intent = new Intent(getApplicationContext(), WarningActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
          }

          mHandler.postDelayed(mRunnable, delayMillis);
        }
 void setExclude(boolean exclude) {
   ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
   List<ActivityManager.AppTask> tasks = am.getAppTasks();
   int taskId = getTaskId();
   for (int i = 0; i < tasks.size(); i++) {
     ActivityManager.AppTask task = tasks.get(i);
     if (task.getTaskInfo().id == taskId) {
       task.setExcludeFromRecents(exclude);
     }
   }
 }
 ActivityManager.AppTask findDocTask() {
   ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
   List<ActivityManager.AppTask> tasks = am.getAppTasks();
   if (tasks != null) {
     for (int i = 0; i < tasks.size(); i++) {
       ActivityManager.AppTask task = tasks.get(i);
       ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
       if (recent.baseIntent != null
           && recent
               .baseIntent
               .getComponent()
               .getClassName()
               .equals(DocActivity.class.getCanonicalName())) {
         return task;
       }
     }
   }
   return null;
 }