android.app.ActivityManager Java Examples
The following examples show how to use
android.app.ActivityManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppUtil.java From FamilyChat with Apache License 2.0 | 7 votes |
/** * 判断某个界面是否在前台 * * @param context * @param className 某个界面名称 */ public static boolean isForeground(Context context, String className) { if (context == null || TextUtils.isEmpty(className)) { return false; } ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1); if (list != null && list.size() > 0) { ComponentName cpn = list.get(0).topActivity; if (className.equals(cpn.getClassName())) { return true; } } return false; }
Example #2
Source File: PackageManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private Intent parseIntentAndUser() throws URISyntaxException { mTargetUser = UserHandle.USER_CURRENT; mBrief = false; mComponents = false; Intent intent = Intent.parseCommandArgs(this, new Intent.CommandOptionHandler() { @Override public boolean handleOption(String opt, ShellCommand cmd) { if ("--user".equals(opt)) { mTargetUser = UserHandle.parseUserArg(cmd.getNextArgRequired()); return true; } else if ("--brief".equals(opt)) { mBrief = true; return true; } else if ("--components".equals(opt)) { mComponents = true; return true; } return false; } }); mTargetUser = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), mTargetUser, false, false, null, null); return intent; }
Example #3
Source File: VideoLoadAsync.java From MediaChooser with Apache License 2.0 | 6 votes |
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) { mImageView = imageView; this.fragment = fragment; mWidth = width; mIsScrolling = isScrolling; final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); final int size = 1024 * 1024 * memClass / 8; // Handle orientation change. GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache(); mCache = c.mRetainedCache; if (mCache == null) { // The maximum bitmap pixels allowed in respective direction. // If exceeding, the cache will automatically scale the // bitmaps. /* final int MAX_PIXELS_WIDTH = 100; final int MAX_PIXELS_HEIGHT = 100;*/ mCache = new GalleryCache(size, mWidth, mWidth); c.mRetainedCache = mCache; } }
Example #4
Source File: ActivityDelegateImpl.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public List<Entry> getTasksFromRecents(boolean isIncognito) { Context context = ContextUtils.getApplicationContext(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<Entry> entries = new ArrayList<Entry>(); for (ActivityManager.AppTask task : activityManager.getAppTasks()) { Intent intent = DocumentUtils.getBaseIntentFromTask(task); if (!isValidActivity(isIncognito, intent)) continue; int tabId = getTabIdFromIntent(intent); if (tabId == Tab.INVALID_TAB_ID) continue; String initialUrl = getInitialUrlForDocument(intent); entries.add(new Entry(tabId, initialUrl)); } return entries; }
Example #5
Source File: ImageManager.java From arcusandroid with Apache License 2.0 | 6 votes |
/** * Enables or disables the disk cache for the life of the application. This method cannot be * called more than once per lifetime of the app and should therefore be called only during * application startup; subsequent calls have no effect on the disk cache state. * * Note that when enabling Piccaso cache indicators, you may still find that some images appear * as though they've been loaded from disk. This will be true for any app-packaged drawable or * bitmap resource that's placed by Picasso. (These are always "from disk" with or without the * presence of a disk cache.) Similarly, it's possible to get green-tagged images when using * Picasso to "load" manually pre-loaded BitmapDrawables. * * @param diskCacheEnabled */ public static void setConfiguration(Context context, boolean diskCacheEnabled, Integer cacheHeapPercent) { try { Picasso.Builder builder = new Picasso.Builder((ArcusApplication.getContext())); if (diskCacheEnabled) { builder.downloader(new OkHttp3Downloader(new OkHttpClient())); } if (cacheHeapPercent != null) { ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); int memoryClass = am.getMemoryClass(); int heapSize = (int) ((float)(1024 * 1024 * memoryClass) * ((float) cacheHeapPercent / 100.0)); builder.memoryCache(new LruCache(heapSize)); logger.debug("Setting Picasso in-memory LRU cache max size to {} bytes; {}% of heap sized {}", heapSize, cacheHeapPercent, 1024 * 1024 * memoryClass); } Picasso.setSingletonInstance(builder.build()); } catch (IllegalStateException e) { logger.warn("Picasso setConfiguration() has already been called; ignoring request."); } }
Example #6
Source File: DefaultMiscActions.java From under-the-hood with Apache License 2.0 | 6 votes |
/** * Starts an {@link AlertDialog} prompt and if accepted will clear the app's data or just opens * the app's info menu if SDK < 19 */ public static void promptUserToClearData(final Context ctx) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { new AlertDialog.Builder(ctx) .setTitle("Clear App Data") .setMessage("Do you really want to clear the whole app data? This cannot be undone.") .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @TargetApi(Build.VERSION_CODES.KITKAT) public void onClick(DialogInterface dialog, int whichButton) { ((ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE)) .clearApplicationUserData(); } }) .setNegativeButton(android.R.string.no, null).show(); } else { ctx.startActivity(getAppInfoIntent(ctx)); } }
Example #7
Source File: RuntimeUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 程序是否在前台运行 * * @param context * @return */ public static boolean isRunningForeground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String curPackageName = context.getPackageName(); List<ActivityManager.RunningAppProcessInfo> app = am.getRunningAppProcesses(); if(app==null){ return false; } for(ActivityManager.RunningAppProcessInfo a:app){ if(a.processName.equals(curPackageName)&& a.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND){ return true; } } return false; }
Example #8
Source File: RecoveryUtil.java From Recovery with Apache License 2.0 | 6 votes |
public static boolean isMainProcess(Context context) { try { ActivityManager am = ((ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE)); List<ActivityManager.RunningAppProcessInfo> processInfo = am.getRunningAppProcesses(); String mainProcessName = context.getPackageName(); int myPid = android.os.Process.myPid(); for (ActivityManager.RunningAppProcessInfo info : processInfo) { if (info.pid == myPid && mainProcessName.equals(info.processName)) { return true; } } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #9
Source File: CommonUtils.java From ans-android-sdk with GNU General Public License v3.0 | 6 votes |
public static String getProcessName() { try { ActivityManager activityManager = (ActivityManager) AnalysysUtil.getContext().getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runningApps = null; if (activityManager != null) { runningApps = activityManager.getRunningAppProcesses(); } if (runningApps == null) { return ""; } String process = ""; for (ActivityManager.RunningAppProcessInfo proInfo : runningApps) { if (proInfo.pid == android.os.Process.myPid()) { if (proInfo.processName != null) { process = proInfo.processName; } } } return process; } catch (Throwable ignore) { ExceptionUtil.exceptionThrow(ignore); return ""; } }
Example #10
Source File: SystemUtils.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
public static boolean isActivityRunning(Context context, String className) { Intent intent = new Intent(); intent.setClassName(context, className); ComponentName cmpName = intent.resolveActivity(context.getPackageManager()); boolean flag = false; if (cmpName != null) { ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfoList = am.getRunningTasks(10); for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) { if (taskInfo.baseActivity.equals(cmpName)) { flag = true; break; } } } return flag; }
Example #11
Source File: IPCInvokeLogic.java From IPCInvoker with Apache License 2.0 | 6 votes |
/** * 判断进程是否存活 */ public static boolean isProcessLive(@NonNull Context context, @NonNull String processName) { if (TextUtils.isEmpty(processName)) { return false; } ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return false; } List<ActivityManager.RunningAppProcessInfo> list = am.getRunningAppProcesses(); if (list == null) { return false; } for(ActivityManager.RunningAppProcessInfo info : list){ if(processName.equals(info.processName)){ return true; } } return false; }
Example #12
Source File: DeviceIdleController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void removePowerSaveTempWhitelistAppChecked(String packageName, int userId) throws RemoteException { getContext().enforceCallingPermission( Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, "No permission to change device idle whitelist"); final int callingUid = Binder.getCallingUid(); userId = ActivityManager.getService().handleIncomingUser( Binder.getCallingPid(), callingUid, userId, /*allowAll=*/ false, /*requireFull=*/ false, "removePowerSaveTempWhitelistApp", null); final long token = Binder.clearCallingIdentity(); try { removePowerSaveTempWhitelistAppInternal(packageName, userId); } finally { Binder.restoreCallingIdentity(token); } }
Example #13
Source File: SettingsActivity.java From rcloneExplorer with MIT License | 6 votes |
private void applyTheme() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1); int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1); boolean isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false); getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true); getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true); if (isDarkTheme) { getTheme().applyStyle(R.style.DarkTheme, true); } else { getTheme().applyStyle(R.style.LightTheme, true); } // set recents app color to the primary color Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round); ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor); setTaskDescription(taskDesc); }
Example #14
Source File: RecentTasks.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
RecentTasks(ActivityManagerService service, ActivityStackSupervisor stackSupervisor) { final File systemDir = Environment.getDataSystemDirectory(); final Resources res = service.mContext.getResources(); mService = service; mUserController = service.mUserController; mTaskPersister = new TaskPersister(systemDir, stackSupervisor, service, this); mGlobalMaxNumTasks = ActivityManager.getMaxRecentTasksStatic(); mHasVisibleRecentTasks = res.getBoolean(com.android.internal.R.bool.config_hasRecents); loadParametersFromResources(res); }
Example #15
Source File: TilesFrameLayout.java From StarWars.Android with MIT License | 6 votes |
private void initGlSurfaceView() { mGLSurfaceView = new StarWarsTilesGLSurfaceView(getContext()); mGLSurfaceView.setBackgroundColor(Color.TRANSPARENT); // Check if the system supports OpenGL ES 2.0. final ActivityManager activityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; if (supportsEs2) { // Request an OpenGL ES 2.0 compatible context. mGLSurfaceView.setEGLContextClientVersion(2); mRenderer = new StarWarsRenderer(mGLSurfaceView, this, mAnimationDuration, mNumberOfTilesX); mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT); mGLSurfaceView.setRenderer(mRenderer); mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGLSurfaceView.setZOrderOnTop(true); } else { throw new UnsupportedOperationException(); } }
Example #16
Source File: StorageUtil.java From mobile-manager-tool with MIT License | 6 votes |
public static void cleanMemory(Context context){ System.out.println("---> 清理前可用内存:"+getAvailMemory(context)+"MB"); ActivityManager activityManager=(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses(); if (processList != null) { for (int i = 0; i < processList.size(); ++i) { RunningAppProcessInfo runningAppProcessInfo= processList.get(i); // 一般数值大于RunningAppProcessInfo.IMPORTANCE_SERVICE // 的进程即为长时间未使用进程或者空进程 // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE // 的进程都是非可见进程,即在后台运行 if (runningAppProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) { String[] pkgList = runningAppProcessInfo.pkgList; for (int j = 0; j < pkgList.length; ++j) { System.out.println("===> 正在清理:"+pkgList[j]); activityManager.killBackgroundProcesses(pkgList[j]); } } } } System.out.println("---> 清理后可用内存:"+getAvailMemory(context)+"MB"); }
Example #17
Source File: ServiceMonitoring.java From retrowatch with Apache License 2.0 | 6 votes |
/** * Check if specified service is running or not * @param context * @param cls name of service * @return boolean is running or not */ private static boolean isRunningService(Context context, Class<?> cls) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> info = activityManager.getRunningServices(Integer.MAX_VALUE); if (info != null) { for(ActivityManager.RunningServiceInfo serviceInfo : info) { ComponentName compName = serviceInfo.service; String className = compName.getClassName(); if(className.equals(cls.getName())) { isRunning = true; break; } } } return isRunning; }
Example #18
Source File: MainActivity.java From rcloneExplorer with MIT License | 6 votes |
private void applyTheme() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); int customPrimaryColor = sharedPreferences.getInt(getString(R.string.pref_key_color_primary), -1); int customAccentColor = sharedPreferences.getInt(getString(R.string.pref_key_color_accent), -1); isDarkTheme = sharedPreferences.getBoolean(getString(R.string.pref_key_dark_theme), false); getTheme().applyStyle(CustomColorHelper.getPrimaryColorTheme(this, customPrimaryColor), true); getTheme().applyStyle(CustomColorHelper.getAccentColorTheme(this, customAccentColor), true); if (isDarkTheme) { getTheme().applyStyle(R.style.DarkTheme, true); } else { getTheme().applyStyle(R.style.LightTheme, true); } TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); getWindow().setStatusBarColor(typedValue.data); // set recents app color to the primary color Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round); ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, customPrimaryColor); setTaskDescription(taskDesc); }
Example #19
Source File: EaseUI.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
/** * check the application process name if process name is not qualified, then we think it is a service process and we will not init SDK * @param pID * @return */ private String getAppName(int pID) { String processName = null; ActivityManager am = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); List l = am.getRunningAppProcesses(); Iterator i = l.iterator(); PackageManager pm = appContext.getPackageManager(); while (i.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next()); try { if (info.pid == pID) { CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA)); // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ // info.processName +" Label: "+c.toString()); // processName = c.toString(); processName = info.processName; return processName; } } catch (Exception e) { // Log.d("Process", "Error>> :"+ e.toString()); } } return processName; }
Example #20
Source File: AppUtils.java From Common with Apache License 2.0 | 6 votes |
/** * Return whether application is foreground. * * @return {@code true}: yes<br>{@code false}: no */ public static boolean isAppForeground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return false; } List<ActivityManager.RunningAppProcessInfo> info = am.getRunningAppProcesses(); if (info == null || info.size() <= 0) { return false; } for (ActivityManager.RunningAppProcessInfo aInfo : info) { if (aInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { if (aInfo.processName.equals(context.getPackageName())) { return true; } } } return false; }
Example #21
Source File: AppWatcher.java From Utils with Apache License 2.0 | 6 votes |
/** * watch for memory usage and heap size per seconds */ public void run() { mTimerTask = new TimerTask() { @Override public void run() { MemoryInfo memoryInfo = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE); activityManager.getMemoryInfo(memoryInfo); Runtime runtime = Runtime.getRuntime(); String msg = String.format("free:%s%% %sKB total:%sKB max:%sKB ", runtime.freeMemory() * 100f / runtime.totalMemory(), runtime.freeMemory(), runtime.totalMemory() / 1024, runtime.maxMemory() / 1024); msg += String.format("native: free:%sKB total:%sKB max:%sKB", android.os.Debug.getNativeHeapFreeSize() / 1024, android.os.Debug.getNativeHeapAllocatedSize() / 1024, android.os.Debug.getNativeHeapSize() / 1024); msg += String.format("| availMem:%sKB", memoryInfo.availMem / 1024); Log.d("memory", msg); } }; mTimer = new Timer(); mTimer.schedule(mTimerTask, 1000, 1000); }
Example #22
Source File: RouterServiceValidator.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method will find which router service is running. Use that info to find out more about that app and service. * It will store the found service for later use and return the package name if found. * @param pm An instance of a package manager. This is no longer used so null can be sent. * @return */ public ComponentName componentNameForServiceRunning(PackageManager pm){ if(context==null){ return null; } ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); //PackageManager pm = context.getPackageManager(); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { //Log.d(TAG, service.service.getClassName()); //We will check to see if it contains this name, should be pretty specific if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)){ //this.service = service.service; //This is great if(service.started && service.restarting==0){ //If this service has been started and is not crashed return service.service; //appPackageForComponenetName(service.service,pm); } } } return null; }
Example #23
Source File: KeyguardDisableHandler.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void updateAllowState() { // We fail safe and prevent disabling keyguard in the unlikely event this gets // called before DevicePolicyManagerService has started. DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( Context.DEVICE_POLICY_SERVICE); if (dpm != null) { try { mAllowDisableKeyguard = dpm.getPasswordQuality(null, ActivityManager.getService().getCurrentUser().id) == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; } catch (RemoteException re) { // Nothing much we can do } } }
Example #24
Source File: ServiceHelper.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public boolean isAppOnForeground() { // Returns a list of application processes that are running on the // device String packageName = context.getPackageName(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses == null) return false; for (RunningAppProcessInfo appProcess : appProcesses) { // importance: // The relative importance level that the system places // on this process. // May be one of IMPORTANCE_FOREGROUND, IMPORTANCE_VISIBLE, // IMPORTANCE_SERVICE, IMPORTANCE_BACKGROUND, or IMPORTANCE_EMPTY. // These constants are numbered so that "more important" values are // always smaller than "less important" values. // processName: // The name of the process that this object is associated with. if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return true; } } return false; }
Example #25
Source File: AppUtil.java From SimpleProject with MIT License | 6 votes |
/** * APP是否在运行中(前台或后台) * @param context * @return */ public static boolean appIsRunning(Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return false; } List<ActivityManager.RunningAppProcessInfo> appList = am.getRunningAppProcesses(); if (appList == null) { return false; } for (ActivityManager.RunningAppProcessInfo appInfo : appList) { if (context.getPackageName().equals(appInfo.processName)) { return true; } } return false; }
Example #26
Source File: ActivityManagerNativeWorker.java From GPT with Apache License 2.0 | 5 votes |
public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() { List<ActivityManager.RunningAppProcessInfo> apps = mTarget.getRunningAppProcesses(); // TODO 临时加上捕获打出日志,这里有发现过crash try { String pluginPkg = Util.getCallingPulingPackage(); if (pluginPkg != null) { int pid = android.os.Process.myPid(); for (ActivityManager.RunningAppProcessInfo app : apps) { if (app.pid == pid) { // 在包名列表里加上插件的包名,小米的ROM在显示Toast之前,会获取RunningProcesses,遍历进程的pkgList,如果没有匹配到, // 认为invisible to user,就不显示了。导致Toast不可用。 String[] pkgList = null; String[] originalList = app.pkgList; if (originalList != null) { pkgList = new String[originalList.length + 1]; System.arraycopy(app.pkgList, 0, pkgList, 0, originalList.length); pkgList[originalList.length] = pluginPkg; } app.processName = pluginPkg; app.pkgList = pkgList; break; } } } } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } } return apps; }
Example #27
Source File: LocationUpdatesService.java From location-samples with Apache License 2.0 | 5 votes |
/** * Returns true if this is a foreground service. * * @param context The {@link Context}. */ public boolean serviceIsRunningInForeground(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService( Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices( Integer.MAX_VALUE)) { if (getClass().getName().equals(service.service.getClassName())) { if (service.foreground) { return true; } } } return false; }
Example #28
Source File: MemoryManagement.java From Effects-Pro with MIT License | 5 votes |
/** * Gets available memory to load image */ public static float free(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); int memoryClass = am.getMemoryClass() - 24; if (memoryClass < 1) memoryClass = 1; return (float) memoryClass; }
Example #29
Source File: MyUtil.java From Clip-Stack with MIT License | 5 votes |
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; }
Example #30
Source File: RunningTasksJellyBean.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @SuppressWarnings("deprecation") @Nullable public String getRunningTasksTop(@NonNull Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); return tasks == null || tasks.isEmpty() ? null : tasks.get(0).topActivity.getPackageName(); }