Android check if service running


/ Published in: Java
Save to your folder(s)

This functions checks if a service is running or not.


Copy this code and paste it in your HTML
  1. private Boolean isServiceRunning(String serviceName) {
  2.  
  3. ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
  4. for (RunningServiceInfo runningServiceInfo : activityManager.getRunningServices(Integer.MAX_VALUE)) {
  5. if (serviceName.equals(runningServiceInfo.service.getClassName())) {
  6. return true;
  7. }
  8. }
  9. return false;
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.