I have an app that gets GPS co-ordinates. It works fine but i want to test from within the calling activity if the service is running. I have the following code that i thought would check but it is returning false when the GPS icon in the notification bar is still flashing. Has anyone any ideas why? Thanks in advance
private boolean isGpsServiceRunning() {
ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("LocationService".equals(service.service.getClassName())) {
return true;
}
}
return false;
}
.
LocalBroadcastManager.getInstance(getApplicationContext())
.registerReceiver(
locationChangereceiver,
new IntentFilter(
LocationChangeIntent.ACTION_LOCATION_CHANGE));
startService(new Intent(this, LocationService.class));
You should compare against LocationService.class.getName(), instead of using a hard coded value. Also, the value that you are using corresponds to the Class#getSimpleName() which is probably not what you want here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With