Java Code Examples for android.app.activitymanager#RunningServiceInfo
The following examples show how to use
android.app.activitymanager#RunningServiceInfo .
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: AppUtils.java From BmapLite with GNU General Public License v3.0 | 6 votes |
/** * 判断某个服务是否正在运行的方法 * * @param context * @param serviceName 是包名+服务的类名(例如:net.loonggg.testbackstage.TestService) * @return true 代表正在运行,false代表服务没有正在运行 */ public static boolean isServiceWork(Context context, String serviceName) { boolean isWork = false; ActivityManager myAM = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> myList = myAM.getRunningServices(30); if (null == myList || myList.isEmpty()) { return false; } for (int i = 0; i < myList.size(); i++) { String mName = myList.get(i).service.getClassName(); if (mName.equals(serviceName)) { isWork = true; break; } } return isWork; }
Example 2
Source File: AcceleraterManager.java From SimplifyReader with Apache License 2.0 | 6 votes |
/** * 用来判断服务是否运行. * @param context * @param className 判断的服务名字 * @return true 在运行 false 不在运行 */ 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(100); 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; } } return isRunning; }
Example 3
Source File: GSAServiceClient.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Get the PSS used by the process hosting a service. * * @param packageName Package name of the service to search for. * @return the PSS in kB of the process hosting a service, or INVALID_PSS. */ @VisibleForTesting static int getPssForService(ComponentName componentName) { if (componentName == null) return INVALID_PSS; Context context = ContextUtils.getApplicationContext(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(1000); if (services == null) return INVALID_PSS; int pid = -1; for (ActivityManager.RunningServiceInfo info : services) { if (componentName.equals(info.service)) { pid = info.pid; break; } } if (pid == -1) return INVALID_PSS; Debug.MemoryInfo infos[] = activityManager.getProcessMemoryInfo(new int[] {pid}); if (infos == null || infos.length == 0) return INVALID_PSS; return infos[0].getTotalPss(); }
Example 4
Source File: VActivityManagerService.java From container with GNU General Public License v3.0 | 6 votes |
@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); } }
Example 5
Source File: NotificationService.java From MediaNotification with Apache License 2.0 | 5 votes |
public static boolean isRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (NotificationService.class.getName().equals(service.service.getClassName())) { return true; } } return false; }
Example 6
Source File: ContactSelectActivity.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
private boolean isServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) 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 7
Source File: ServiceStarterTest.java From JayPS-AndroidApp with MIT License | 5 votes |
private void setupMockServiceStopped() { ActivityManager manager = mock(ActivityManager.class); ArrayList<ActivityManager.RunningServiceInfo> runningServices = new ArrayList<ActivityManager.RunningServiceInfo>(); ActivityManager.RunningServiceInfo info = new ActivityManager.RunningServiceInfo(); info.service = new ComponentName(MainService.class.getPackage().getName(),GPSStatus.class.getName()); runningServices.add(info); when(manager.getRunningServices(Integer.MAX_VALUE)).thenReturn(runningServices); when(_mockContext.getSystemService(getContext().ACTIVITY_SERVICE)).thenReturn(manager); }
Example 8
Source File: ContextReference.java From Navigator with Apache License 2.0 | 5 votes |
static String isAlive(Service candidate) { if (candidate == null) return "Service reference null"; ActivityManager manager = (ActivityManager) candidate.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE); if (services == null) return "Could not retrieve services from service manager"; for (ActivityManager.RunningServiceInfo service : services) { if (candidate.getClass().getName().equals(service.service.getClassName())) { return null; } } return "Service stopped"; }
Example 9
Source File: ProfileActivity.java From loco-answers with GNU General Public License v3.0 | 5 votes |
private boolean isServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) 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 10
Source File: MainActivity.java From Hook with Apache License 2.0 | 5 votes |
public boolean isRunning() { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo rsi : am.getRunningServices(Integer.MAX_VALUE)) { String pkgName = rsi.service.getPackageName(); if (pkgName.equals(Constans.ALIPAY_PACKAGE)) { if (rsi.process.equals(Constans.ALIPAY_PACKAGE)) { return true; } } } return false; }
Example 11
Source File: MainActivity.java From SMS2Email with Apache License 2.0 | 5 votes |
private boolean isServiceRunning(int uid, String name) { List<ActivityManager.RunningServiceInfo> serviceList = ((ActivityManager)getSystemService (Context.ACTIVITY_SERVICE)).getRunningServices(Integer.MAX_VALUE); for(ActivityManager.RunningServiceInfo info: serviceList) { if(info.uid == uid) { return true; } } return false; }
Example 12
Source File: ToolBox.java From privacy-friendly-netmonitor with GNU General Public License v3.0 | 5 votes |
public static boolean isAnalyzerServiceRunning() { ActivityManager manager = (ActivityManager) RunStore.getContext().getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (PassiveService.class.getName().equals(service.service.getClassName())) { return true; } } return false; }
Example 13
Source File: AerlinkActivity.java From Aerlink-for-Android with MIT License | 5 votes |
/*** * Check if Aerlink's main service is running * @return boolean indicating if the service is running or not */ public boolean isServiceRunning() { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (MainService.class.getName().equals(service.service.getClassName())) { return true; } } return false; }
Example 14
Source File: SMSReceiverService.java From SimpleSmsRemote with MIT License | 5 votes |
public static boolean isRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (SMSReceiverService.class.getName().equals(service.service.getClassName())) { return true; } } return false; }
Example 15
Source File: ServiceUtil.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Checks the specified service is running. * @param service * @param context * @return */ public static boolean isServiceRunning(Class<? extends Service> service, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo runningServiceInfo : manager.getRunningServices(Integer.MAX_VALUE)) { if (service.getName().equals(runningServiceInfo.service.getClassName())) { return true; } } return false; }
Example 16
Source File: Util.java From Inspeckage with Apache License 2.0 | 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 17
Source File: StarterService.java From always-on-amoled with GNU General Public License v3.0 | 5 votes |
private boolean isServiceRunning(Class<?> serviceClass) { String TAG = serviceClass.getSimpleName(); String serviceTag = serviceClass.getSimpleName(); ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { Utils.logDebug(TAG, "Is already running"); return true; } } Utils.logDebug(serviceTag, "Is not running"); return false; }
Example 18
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 19
Source File: Utils.java From AudioAnchor with GNU General Public License v3.0 | 5 votes |
static boolean isMediaPlayerServiceRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (manager != null) { for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (MediaPlayerService.class.getName().equals(service.service.getClassName())) { return true; } } } return false; }
Example 20
Source File: AppHelper.java From Utils with Apache License 2.0 | 5 votes |
/** * whether the service is running. */ public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService( Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo si : servicesList) { if (className.equals(si.service.getClassName())) { isRunning = true; } } return isRunning; }