Java
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.dir.pack.DemoService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
Here in the if condition we need to give the service file name with the package. So on the checking area you can simply call this function in the if statement like
Java
if(isMyServiceRunning()) {
System.out.println("Service is running");
} else {
System.out.println("Service is not running");
}
Have a nice day