在我的应用程序中,我有一个广播接收器,它在收到SMS消息中的关键字后开始跟踪手机GPS位置的服务。我做到这一点使用 -如何从广播接收器中取消注册听众和停止服务
context.startService(new Intent(context,TrackGPS.class));
我还需要能够在在SMS消息接收另一个关键字停止服务,我试图做到这一点,但GPS传感器仍然跟踪定位和GPS图标闪烁时屏幕的顶部。我试图这样做 -
context.stopService(new Intent(context, TrackGPS.class));
我想这可能是因为GPS侦听器需要注销。任何人都可以帮助我获得这项服务,在收到文字后停止+停止GPS跟踪?提前致谢。
解决方案
@Override
public int onStartCommand(Intent GPSService, int flags, int startId) {
boolean startListening = GPSService.getExtras().getBoolean("IsStartTracking");
if (startListening == true){
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
else {
lm.removeUpdates(this);
stopSelf();
}
return 1;
}
搞乱了这个方法之后,我弄明白了,你是传奇!我会在上面发布我的代码,因为onStart方法已被弃用。 – bobby123 2011-01-25 18:16:17