我有一个获得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));
解决方法:
您应该与LocationService.class.getname()进行比较,而不是使用硬编码值.此外,您使用的值对应于Class#getSimpleName(),这可能不是您想要的.
总结以上是内存溢出为你收集整理的android如何检查服务是否正在运行全部内容,希望文章能够帮你解决android如何检查服务是否正在运行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)