我有一个应用程序可以获取GPS坐标。它运行良好,但我想从调用活动内部测试服务是否正在运行。我有以下代码,我认为会检查,但当通知栏中的GPS图标仍在闪烁时,它返回false。有人有任何想法吗?提前感谢。
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));