public static String getCurProcessName(Context context) { int pid = android.os.Process.myPid(); ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : activityManager .getRunningAppProcesses()) { if (appProcess.pid == pid) { return appProcess.processName; } } return null; }
/** * whether this process is named with processName * * @param context * @param processName * @return <ul> * return whether this process is named with processName * <li>if context is null, return false</li> * <li>if {@link ActivityManager#getRunningAppProcesses()} is null, return false</li> * <li>if one process of {@link ActivityManager#getRunningAppProcesses()} is equal to processName, return * true, otherwise return false</li> * </ul> */ public static boolean isNamedProcess(Context context, String processName) { if (context == null) { return false; } int pid = android.os.Process.myPid(); ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses(); if (ListUtils.isEmpty(processInfoList)) { return false; } for (RunningAppProcessInfo processInfo : processInfoList) { if (processInfo != null && processInfo.pid == pid && ObjectUtils.isEquals(processName, processInfo.processName)) { return true; } } return false; }
/** * Exclude the app from the recent tasks list. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void excludeFromTaskList() { ActivityManager am = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); if (am == null || Build.VERSION.SDK_INT < 21) return; List<AppTask> tasks = am.getAppTasks(); if (tasks == null || tasks.isEmpty()) return; tasks.get(0).setExcludeFromRecents(true); }
private String getAppName(int pID) { String processName = null; ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List l = am.getRunningAppProcesses(); Iterator i = l.iterator(); while (i.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next()); try { if (info.pid == pID) { processName = info.processName; return processName; } } catch (Exception e) { // Log.d("Process", "Error>> :"+ e.toString()); } } return null; }
void init(OpenGLEngine engine) { // Check if the system supports OpenGL ES 2.0. final ActivityManager activityManager = (ActivityManager) 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. engine.setEGLContextClientVersion(2); // Set the renderer to our user-defined renderer. engine.setRenderer(getNewRenderer()); } else { // This is where you could create an OpenGL ES 1.x compatible // renderer if you wanted to support both ES 1 and ES 2. return; } }
private void queryRunningService() { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceInfoList = manager.getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfoList) { Log.d(TAG, "queryRunningService: \n" + "process:" + serviceInfo.process + "\n---service:" + serviceInfo.service.flattenToString() + "\n---pid:" + serviceInfo.pid + "\n---uid:" + serviceInfo.uid + "\n---clientPackage:" + serviceInfo.clientPackage + "\n---lastActivityTime:" + serviceInfo.lastActivityTime); } }
/** * Check if a service is running * * @param context The context * @param serviceClass The class of the service to check * @return true if it is, false if not. */ public static boolean isServiceRunning(Context context, Class<?> serviceClass) { if(context == null){ throw new IllegalArgumentException("Context cannot be null"); } if(serviceClass == null){ throw new IllegalArgumentException("Class cannot be null"); } ActivityManager manager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); if(manager == null){ return false; } for (ActivityManager.RunningServiceInfo service : manager .getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; }
private boolean isForeground(Context context) { try { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses(); if (runningAppProcesses != null) { int myPid = android.os.Process.myPid(); for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { if (runningAppProcessInfo.pid == myPid) { return runningAppProcessInfo.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; } } } } catch (Exception e) { Log.e(TAG, "e:", e); } return false; }
@Override protected void tearDown() throws Exception { int counter = 10; if (testRealm != null) { testRealm.close(); } getContext().unbindService(serviceConnection); remoteMessenger = null; // Kills the remote process. ActivityManager.RunningAppProcessInfo info = getRemoteProcessInfo(); if (info != null) { android.os.Process.killProcess(info.pid); } while (getRemoteProcessInfo() != null) { if (counter == 0) { assertTrue("The remote service process is still alive.", false); } Thread.sleep(300); counter--; } super.tearDown(); }
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; } } } } } else { List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(context.getPackageName())) { isInBackground = false; } } return isInBackground; }
/** * 退出应用程序 */ public void appExit() { try { killAll(); release(); if (mActivityList != null) mActivityList = null; ActivityManager activityMgr = (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE); activityMgr.killBackgroundProcesses(mApplication.getPackageName()); mApplication = null; activityMgr = null; System.exit(0); for (int i = 0; i < 100; i++) { System.gc(); } } catch (Exception e) { e.printStackTrace(); } }
/** * 判断service是否正在运行 * * @param mContext * @param className * @return */ public static boolean isServiceRunning(Context mContext, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(200); if (!(serviceList.size() > 0)) { return false; } for (int i = 0; i < serviceList.size(); i++) { if (serviceList.get(i).service.getClassName().equals(className) == true) { isRunning = true; break; } // Log.d("Service:", "isServiceRunning: "+serviceList.get(i).service.getClassName()); } return isRunning; }
/** * 退出应用程序 * * @param context 上下文 * @param isBackground 是否开开启后台运行 */ public void AppExit(Context context, Boolean isBackground) { try { finishAllActivity(); ActivityManager activityMgr = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); activityMgr.restartPackage(context.getPackageName()); } catch (Exception e) { } finally { // 注意,如果您有后台程序运行,请不要支持此句子 if (!isBackground) { System.exit(0); } } }
public static boolean isAppOnForeground(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> list = manager.getRunningAppProcesses(); if (list == null) { return false; } for (ActivityManager.RunningAppProcessInfo info : list) { if (info.processName.equals(context.getPackageName())) { // BACKGROUND=400 EMPTY=500 FOREGROUND=100 // GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=20 if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return true; } } } return false; }
public static boolean checkIsMainProcess(Application app) { ActivityManager activityManager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses(); if (null == runningAppProcessInfoList) { return false; } String currProcessName = null; int currPid = android.os.Process.myPid(); //find the process name for (RunningAppProcessInfo processInfo : runningAppProcessInfoList) { if (null != processInfo && processInfo.pid == currPid) { currProcessName = processInfo.processName; } } //is current process the main process if (!TextUtils.equals(currProcessName, app.getPackageName())) { return false; } return true; }
@Override public VParceledListSlice<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags, int userId) { synchronized (mHistory) { List<ActivityManager.RunningServiceInfo> services = new ArrayList<>(mHistory.size()); for (ServiceRecord r : mHistory) { if (r.process.userId != userId) { continue; } ActivityManager.RunningServiceInfo info = new ActivityManager.RunningServiceInfo(); info.uid = r.process.vuid; info.pid = r.process.pid; ProcessRecord processRecord = findProcessLocked(r.process.pid); if (processRecord != null) { info.process = processRecord.processName; info.clientPackage = processRecord.info.packageName; } info.activeSince = r.activeSince; info.lastActivityTime = r.lastActivityTime; info.clientCount = r.getClientCount(); info.service = ComponentUtils.toComponentName(r.serviceInfo); info.started = r.startId > 0; } return new VParceledListSlice<>(services); } }
/** * 判断某个服务是否正在运行的方法 * * @param mContext * @param serviceName * 是包名+服务的类名(例如:net.loonggg.testbackstage.TestService) * @return true代表正在运行,false代表服务没有正在运行 */ public boolean isServiceWork(Context mContext, String serviceName) { boolean isWork = false; ActivityManager myAM = (ActivityManager) mContext .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> myList = myAM.getRunningServices(40); if (myList.size() <= 0) { return false; } for (int i = 0; i < myList.size(); i++) { String mName = myList.get(i).service.getClassName().toString(); if (mName.equals(serviceName)) { isWork = true; break; } } return isWork; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //最近列表显示的缩略图的label,icon,top bar color if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription( getTitle().toString(), BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round)); setTaskDescription(taskDesc); } setContentView(initContentView()); initStatusBar(); initToolbar(); init(); initView(); initData(); }
private void updateTaskDescription(int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String title = getTitle().toString(); Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager()); Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null; int colorPrimary; if (position < slidesAdapter.getCount()) { colorPrimary = ContextCompat.getColor(this, slidesAdapter.slides.get(position).backgroundColor); } else { TypedValue typedValue = new TypedValue(); TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary}); colorPrimary = a.getColor(0, 0); a.recycle(); } colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF); setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary)); } }
private void b() { mHandler.sendEmptyMessage(0x1); ActivityManager activityManager = (ActivityManager)smali_layout_apktool.this.getSystemService(ACTIVITY_SERVICE); if (processNamelist != null && processNamelist.size() > 0) { for (String processName : processNamelist) { activityManager.killBackgroundProcesses(processName); } } mHandler.sendEmptyMessageDelayed(0x2, 2000); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.io_root); StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary)); ListView sa=(ListView)findViewById(R.id.mainListView1); try { ActivityManager qw=(ActivityManager)io_styTool.this.getSystemService(ACTIVITY_SERVICE); ArrayList<String> ary=new ArrayList<String>(); List<ActivityManager.RunningAppProcessInfo> act=qw.getRunningAppProcesses(); int i=1; for (ActivityManager.RunningAppProcessInfo a:act) { ary.add((i++) + ": " + a.processName + "\n" + " id " + a.pid + " uid " + a.uid); } ArrayAdapter shi=new ArrayAdapter<String>(io_styTool.this, android.R.layout.simple_list_item_1, ary); sa.setAdapter(shi); } catch (Exception e) { Toast.makeText(io_styTool.this, e.toString(), Toast.LENGTH_LONG).show(); } }
/** * get top activity * @param context * @return */ public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else return ""; }
@Override public void onAttach(Activity activity) { logd("onAttach(%s)", activity.getClass().getSimpleName()); super.onAttach(activity); mContext = activity; mPm = mContext.getPackageManager(); mNoMan = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); try { mListener.registerAsSystemService(mContext, new ComponentName(mContext.getPackageName(), this.getClass().getCanonicalName()), ActivityManager.getCurrentUser()); } catch (RemoteException e) { Log.e(TAG, "Cannot register listener", e); } }
private List<HistoricalNotificationInfo> loadNotifications() { final int currentUserId = ActivityManager.getCurrentUser(); try { StatusBarNotification[] active = mNoMan.getActiveNotifications( mContext.getPackageName()); StatusBarNotification[] dismissed = mNoMan.getHistoricalNotifications( mContext.getPackageName(), 50); List<HistoricalNotificationInfo> list = new ArrayList<HistoricalNotificationInfo>(active.length + dismissed.length); for (StatusBarNotification[] resultset : new StatusBarNotification[][] { active, dismissed }) { for (StatusBarNotification sbn : resultset) { final HistoricalNotificationInfo info = new HistoricalNotificationInfo(); info.pkg = sbn.getPackageName(); info.user = sbn.getUserId(); info.icon = loadIconDrawable(info.pkg, info.user, sbn.getNotification().icon); info.pkgicon = loadPackageIconDrawable(info.pkg, info.user); info.pkgname = loadPackageName(info.pkg); if (sbn.getNotification().extras != null) { info.title = sbn.getNotification().extras.getString( Notification.EXTRA_TITLE); if (info.title == null || "".equals(info.title)) { info.title = sbn.getNotification().extras.getString( Notification.EXTRA_TEXT); } } if (info.title == null || "".equals(info.title)) { info.title = sbn.getNotification().tickerText; } // still nothing? come on, give us something! if (info.title == null || "".equals(info.title)) { info.title = info.pkgname; } info.timestamp = sbn.getPostTime(); info.priority = sbn.getNotification().priority; logd(" [%d] %s: %s", info.timestamp, info.pkg, info.title); info.active = (resultset == active); if (info.user == UserHandle.USER_ALL || info.user == currentUserId) { list.add(info); } } } return list; } catch (RemoteException e) { Log.e(TAG, "Cannot load Notifications: ", e); } return null; }
public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { /* BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=200 */ Log.i(context.getPackageName(), "此appimportace =" + appProcess.importance + ",context.getClass().getName()=" + context.getClass().getName()); if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { Log.i(context.getPackageName(), "处于后台" + appProcess.processName); return true; } else { Log.i(context.getPackageName(), "处于前台" + appProcess.processName); return false; } } } return false; }
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; }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { ActivityManager.TaskDescription td = (ActivityManager.TaskDescription) args[1]; String label = td.getLabel(); Bitmap icon = td.getIcon(); // If the activity label/icon isn't specified, the application's label/icon is shown instead // Android usually does that for us, but in this case we want info about the contained app, not VIrtualApp itself if (label == null || icon == null) { Application app = VClientImpl.get().getCurrentApplication(); if (app != null) { try { if (label == null) { label = app.getApplicationInfo().loadLabel(app.getPackageManager()).toString(); } if (icon == null) { Drawable drawable = app.getApplicationInfo().loadIcon(app.getPackageManager()); if (drawable != null) { icon = DrawableUtils.drawableToBitMap(drawable); } } td = new ActivityManager.TaskDescription(label, icon, td.getPrimaryColor()); } catch (Throwable e) { e.printStackTrace(); } } } TaskDescriptionDelegate descriptionDelegate = VirtualCore.get().getTaskDescriptionDelegate(); if (descriptionDelegate != null) { td = descriptionDelegate.getTaskDescription(td); } args[1] = td; return method.invoke(who, args); }
/** * whether application is in background * <ul> * <li>need use permission android.permission.GET_TASKS in Manifest.xml</li> * </ul> * * @param context * @return if application is in background return true, otherwise return false */ public static boolean isApplicationInBackground(Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskList = am.getRunningTasks(1); if (taskList != null && !taskList.isEmpty()) { ComponentName topActivity = taskList.get(0).topActivity; if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
public boolean isEngineLaunched() { String engineProcessName = getEngineProcessName(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) { if (info.processName.endsWith(engineProcessName)) { return true; } } return false; }
private String getProcessName(int pid) { for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) { if (info.pid == pid) { return info.processName; } } return null; }
public static boolean isSingleActivity(Context var0) { ActivityManager var1 = (ActivityManager) var0.getSystemService("activity_message"); List var2 = null; try { var2 = var1.getRunningTasks(1); } catch (SecurityException var4) { var4.printStackTrace(); } return var2 != null && var2.size() >= 1 ? ((ActivityManager.RunningTaskInfo) var2.get(0)).numRunning == 1 : false; }
public String getEmulatorName(Context context) { String sEmulatorName = null; final PackageManager packageManager = context.getPackageManager(); List<ApplicationInfo> packages = packageManager .getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { String packageName = packageInfo.packageName; if (packageName.startsWith("com.vphone.") || packageName.startsWith("com.bignox.")) { sEmulatorName = context.getString(R.string.emulator_name_yeshen); } else if (packageName.startsWith("me.haima.")) { sEmulatorName = context.getString(R.string.emulator_name_haimawan); } else if (packageName.startsWith("com.bluestacks.")) { sEmulatorName = context.getString(R.string.emulator_name_bluestacks); } else if (packageName.startsWith("cn.itools.")&&(Build.PRODUCT.startsWith("iToolsAVM")||Build.MANUFACTURER.startsWith("iToolsAVM")||Build.DEVICE.startsWith("iToolsAVM")||Build.MODEL.startsWith("iToolsAVM")||Build.BRAND.startsWith("generic")||Build.HARDWARE.startsWith("vbox86"))) { sEmulatorName = context.getString(R.string.emulator_name_itools); } else if (packageName.startsWith("com.kop.") || packageName.startsWith("com.kaopu.")) { sEmulatorName = context.getString(R.string.emulator_name_tiantian); } else if (packageName.startsWith("com.microvirt.")) { sEmulatorName = context.getString(R.string.emulator_name_xiaoyao); } else if (packageName.equals("com.google.android.launcher.layouts.genymotion")) { sEmulatorName = getString(R.string.emulator_name_genymotion); } } if (sEmulatorName == null) { ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceInfos = manager.getRunningServices(30); for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfos) { String serviceName = serviceInfo.service.getClassName(); if (serviceName.startsWith("com.bluestacks.")) { sEmulatorName = context.getString(R.string.emulator_name_bluestacks); } } } if (sEmulatorName == null && Build.PRODUCT.startsWith("sdk_google")) { sEmulatorName = context.getString(R.string.emulator_name_android); } return sEmulatorName == null ? "" : sEmulatorName; }
public static String getCurProcessName(Context ctx) { int pid = android.os.Process.myPid(); ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); if (activityManager == null || activityManager.getRunningAppProcesses() == null) { return null; } for (ActivityManager.RunningAppProcessInfo processInfo : activityManager.getRunningAppProcesses()) { if (processInfo.pid == pid) { return processInfo.processName; } } return null; }
private static boolean isLowMemoryDevice(ActivityManager activityManager) { // Explicitly check with an if statement, on some devices both parts of boolean expressions // can be evaluated even if we'd normally expect a short circuit. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return activityManager.isLowRamDevice(); } else { return false; } }
/** * 获取后台服务进程 * <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p> * * @return 后台服务进程 */ public static Set<String> getAllBackgroundProcesses() { ActivityManager am = (ActivityManager) Utils.getContext().getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses(); Set<String> set = new HashSet<>(); for (ActivityManager.RunningAppProcessInfo info : infos) { Collections.addAll(set, info.pkgList); } return set; }
public synchronized static ContactPictureCache getInstance(Context context) { if (sInstance == null) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); sMemClass = activityManager.getMemoryClass(); sInstance = new ContactPictureCache(); } return sInstance; }
@TargetApi(VERSION_CODES.KITKAT) public static boolean isLowMemory(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); return (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) || activityManager.getMemoryClass() <= 64; }
public static boolean isServerRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> runningServices = manager.getRunningServices(Integer.MAX_VALUE); String ftpServiceClassName = ConnectionsService.class.getName(); for (ActivityManager.RunningServiceInfo service : runningServices) { String currentClassName = service.service.getClassName(); if (ftpServiceClassName.equals(currentClassName)) { return true; } } return false; }
@Override protected void onDestroy() { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (CacheService.class.getName().equals(service.service.getClassName())) { stopService(new Intent(this, CacheService.class)); } } super.onDestroy(); }