List of usage examples for android.app ActivityManager getRunningTasks
@Deprecated public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException
From source file:cm.aptoide.pt.Aptoide.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); keepScreenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power"); DownloadQueueServiceIntent = new Intent(getApplicationContext(), DownloadQueueService.class); startService(DownloadQueueServiceIntent); //@dsilveira #534 +10lines Check if Aptoide is already running to avoid wasting time and showing the splash ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> running = activityManager.getRunningTasks(Integer.MAX_VALUE); for (RunningTaskInfo runningTask : running) { if (runningTask.baseActivity.getClassName().equals("cm.aptoide.pt.RemoteInTab")) { //RemoteInTab is the real Aptoide Activity Message msg = new Message(); msg.what = LOAD_TABS;//www . jav a 2 s .c o m startHandler.sendMessage(msg); return; } } Log.d("Aptoide", "******* \n Downloads will be made to: " + Environment.getExternalStorageDirectory().getPath() + "\n ********"); sPref = getSharedPreferences("aptoide_prefs", MODE_PRIVATE); prefEdit = sPref.edit(); db = new DbHandler(this); PackageManager mPm = getPackageManager(); try { pkginfo = mPm.getPackageInfo("cm.aptoide.pt", 0); } catch (NameNotFoundException e) { } requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { if (pkginfo.versionCode < Integer.parseInt(getXmlElement("versionCode"))) { Log.d("Aptoide-VersionCode", "Using version " + pkginfo.versionCode + ", suggest update!"); requestUpdateSelf(); } else { proceed(); } } catch (Exception e) { e.printStackTrace(); proceed(); } }
From source file:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java
/** * @param packageName//from ww w . j a v a 2 s .com * @return checks if a particular application is in the foreground */ public boolean isForeground(final String packageName) { // Get the Activity Manager ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); // Get a list of running tasks, we are only interested in the last one, // the top most so we give a 1 as parameter so we only get the topmost. final List<ActivityManager.RunningTaskInfo> task = manager.getRunningTasks(1); // Get the info we need for comparison. final ComponentName componentInfo = task.get(0).topActivity; // Check if it matches our package name. if (componentInfo.getPackageName().equals(packageName) && componentInfo.getClassName().contains("SecondActivity")) return true; // If not then our app is not on the foreground. return false; }
From source file:org.deviceconnect.android.deviceplugin.host.profile.HostTouchProfile.java
/** * Execute Touch Profile Activity.// w w w . ja v a2s .com * * @param serviceId service ID. * @return Always true. */ private boolean execTouchProfileActivity(final String serviceId) { ActivityManager mActivityManager = (ActivityManager) getContext() .getSystemService(Service.ACTIVITY_SERVICE); String mClassName = mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName(); if (!(TouchProfileActivity.class.getName().equals(mClassName))) { Intent mIntent = new Intent(); mIntent.setClass(getContext(), TouchProfileActivity.class); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mIntent.putExtra(DConnectMessage.EXTRA_SERVICE_ID, serviceId); this.getContext().startActivity(mIntent); } return true; }
From source file:at.vcity.androidimsocket.services.IMService.java
public boolean isForeground(String myPackage) { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; return componentInfo.getPackageName().equals(myPackage); }
From source file:com.example.finalfcm.MyFirebaseMessagingService.java
private boolean isAppIsInBackground(Context context) { boolean isInBackground = true; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(context.getPackageName())) { isInBackground = false; }/*from www . jav a2 s.c om*/ } } } } else { List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(context.getPackageName())) { isInBackground = false; } } return isInBackground; }
From source file:com.air.mobilebrowser.BrowserActivity.java
@Override public void onPause() { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); ComponentName topActivity = tasks.get(0).topActivity; String packageName = topActivity.getPackageName(); if (!packageName.equals(super.getPackageName()) && !packageName.equals("android")) { mBeenBackgrounded = true;/*from ww w . j a v a2s .c o m*/ executeAIRMobileFunction(JSNTVCmds.NTV_ENTER_BACKGROUND, null); } mWebView.onPause(); super.onPause(); }
From source file:com.android.mms.transaction.MessagingNotification.java
private static void notifyUserIfFullScreen(Context context, String from) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1); if (runningTasks.size() > 0) { String topActivity = runningTasks.get(0).topActivity.getClassName(); Log.d(TAG, "checkIsFullScreenMode: the top activity is: " + topActivity); if ((topActivity != null) && (topActivity.equals("com.android.browser.BrowserActivity"))) { Intent intent = new Intent("com.android.mms.transaction.MESSAGE_RECEIVED"); intent.putExtra("from", from); context.sendBroadcast(intent); }/* w w w . ja v a 2 s.c o m*/ } }
From source file:lewa.support.v7.app.ActionBarActivityDelegateBase.java
public boolean isHome() { if (!IS_IGNORE_HOME) { try {//from w w w . j ava 2 s. c o m ActivityManager mActivityManager = (ActivityManager) mActivity .getSystemService(Context.ACTIVITY_SERVICE); if (mActivityManager != null) { List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(1); // boolean isLauncherClass = // rti.get(0).topActivity.getClassName() // .equals("com.lewa.launcher.Launcher"); // Log.i(TAG,"isLauncherClass :"+rti.get(0).topActivity.getClassName()); if (rti != null) { if (rti.size() != 0) { ComponentName cn = rti.get(0).topActivity; if (cn != null) { return getHomes().contains(cn.getPackageName()); } } } } } catch (Exception e) { } } // return false; }
From source file:com.paywith.ibeacon.service.IBeaconService.java
public boolean isForeground(String myPackage) { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(myPackage)) { return true; }/*from w w w.j a v a 2 s. com*/ return false; }
From source file:com.farmerbb.taskbar.service.TaskbarService.java
@SuppressWarnings("deprecation") private List<AppEntry> getAppEntriesUsingActivityManager(int maxNum) { ActivityManager mActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> usageStatsList = mActivityManager.getRunningTasks(maxNum); List<AppEntry> entries = new ArrayList<>(); for (ActivityManager.RunningTaskInfo usageStats : usageStatsList) { AppEntry newEntry = new AppEntry(usageStats.baseActivity.getPackageName(), null, null, null, false); entries.add(newEntry);//from w w w. j a v a 2 s . c o m } return entries; }