List of usage examples for android.app ActivityManager getRunningTasks
@Deprecated public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException
From source file:Main.java
/** * Method checks if the app is in background or not */// w w w .j av a2 s. com public static 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; } } } } } 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:free.yhc.netmbuddy.utils.Utils.java
public static String getCurrentTopActivity() { ActivityManager am = (ActivityManager) getAppContext().getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); ActivityManager.RunningTaskInfo ar = tasks.get(0); return ar.topActivity.getClassName().toString(); }
From source file:com.neal.repairer.ease.receiver.CallReceiver.java
private boolean isRunningForeground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; String currentPackageName = cn.getPackageName(); if (!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(context.getPackageName())) { return true; }//from ww w. j a v a2 s .c o m return false; }
From source file:com.entropy.promoenginedemoapp.gcm.MyGcmListenerService.java
private boolean isApplicationSentToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }//from ww w. java 2s .c o m } return false; }
From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java
public boolean isRunning() { ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE); for (ActivityManager.RunningTaskInfo task : tasks) { if (getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName())) return true; }/*w w w . ja v a 2s .c om*/ return false; }
From source file:org.deviceconnect.android.deviceplugin.host.profile.HostCanvasProfile.java
/** * ??????Activity????./* w ww. j av a2 s. co m*/ * * @return ?? */ private String getClassnameOfTopActivity() { ActivityManager activityMgr = (ActivityManager) getContext().getSystemService(Service.ACTIVITY_SERVICE); return activityMgr.getRunningTasks(1).get(0).topActivity.getClassName(); }
From source file:cmu.troy.applogger.AppService.java
private List<String> getCurrentApps() { Context context = this.getApplicationContext(); ActivityManager mgr = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = mgr.getRunningTasks(100); ArrayList<String> res = new ArrayList<String>(); for (Iterator<RunningTaskInfo> i = tasks.iterator(); i.hasNext();) { RunningTaskInfo p = (RunningTaskInfo) i.next(); res.add(p.baseActivity.flattenToString()); }//from www .jav a2s. com return res; }
From source file:org.solovyev.android.messenger.UnreadMessagesNotifier.java
@Nullable private ActivityManager.RunningTaskInfo getForegroundTask() { final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); // The first in the list of RunningTasks is always the foreground task. final List<ActivityManager.RunningTaskInfo> foregroundTasks = am.getRunningTasks(1); if (foregroundTasks != null && !foregroundTasks.isEmpty()) { return foregroundTasks.get(0); } else {/*from w ww . ja va2 s . com*/ return null; } }
From source file:com.quarterfull.newsAndroid.services.OwnCloudSyncService.java
private void finishedSync() { TeslaUnreadManager.PublishUnreadCount(this); WidgetProvider.UpdateWidget(this); syncRunning = false;/* ww w . ja va 2 s . co m*/ syncStopWatch.stop(); Log.v(TAG, "Time needed (synchronization): " + syncStopWatch.toString()); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this); int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0); if (newItemsCount > 0) { ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; if (!componentInfo.getPackageName().equals("com.quarterfull.newsAndroid")) { Resources res = getResources(); String tickerText = res.getQuantityString(R.plurals.notification_new_items_ticker, newItemsCount, newItemsCount); String contentText = res.getQuantityString(R.plurals.notification_new_items_text, newItemsCount, newItemsCount); String title = getString(R.string.app_name); if (mPrefs.getBoolean(SettingsActivity.CB_SHOW_NOTIFICATION_NEW_ARTICLES_STRING, true))//Default is true NotificationManagerNewsReader.getInstance(OwnCloudSyncService.this).ShowMessage(title, tickerText, contentText); } } EventBus.getDefault().post(new SyncFinishedEvent()); }
From source file:net.bither.AndroidImplAbstractApp.java
@Override public ISetting initSetting() { return new ISetting() { @Override/*from www .j a v a 2 s . c o m*/ public BitherjSettings.AppMode getAppMode() { return AppSharedPreference.getInstance().getAppMode(); } @Override public boolean getBitherjDoneSyncFromSpv() { return AppSharedPreference.getInstance().getBitherjDoneSyncFromSpv(); } @Override public void setBitherjDoneSyncFromSpv(boolean isDone) { AppSharedPreference.getInstance().setBitherjDoneSyncFromSpv(isDone); } @Override public BitherjSettings.TransactionFeeMode getTransactionFeeMode() { return AppSharedPreference.getInstance().getTransactionFeeMode(); } @Override public BitherjSettings.ApiConfig getApiConfig() { return AppSharedPreference.getInstance().getApiConfig(); } @Override public File getPrivateDir(String dirName) { File file = BitherApplication.mContext.getDir(dirName, Context.MODE_PRIVATE); if (!file.exists()) { file.mkdirs(); } return file; } @Override public boolean isApplicationRunInForeground() { if (BitherApplication.mContext == null) { return false; } ActivityManager am = (ActivityManager) BitherApplication.mContext .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (tasks != null && !tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(BitherApplication.mContext.getPackageName())) { return false; } } return true; } @Override public QRCodeUtil.QRQuality getQRQuality() { return AppSharedPreference.getInstance().getQRQuality(); } @Override public boolean getDownloadSpvFinish() { return AppSharedPreference.getInstance().getDownloadSpvFinish(); } @Override public void setDownloadSpvFinish(boolean finish) { AppSharedPreference.getInstance().setDownloadSpvFinish(finish); } @Override public CookieStore getCookieStore() { return PersistentCookieStore.getInstance(); } }; }