我有一个获取 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));