我的代码是
public class AlarmService extends Service implements LocationListener {
public int onStartCommand(Intent intent,int flags,int startId){
getLocation();
if(reachedLocation()){
Intent alarmIntent=new Intent(getApplicationContext(),MainActivity.class);
startActivity(alarmIntent);
stopSelf();
}
@Override
public void onLocationChanged(Location location) {
getLocation();
if(reachedLocation()){
Intent alarmIntent=new Intent(getApplicationContext(),MainActivity.class);
startActivity(alarmIntent);
stopSelf();
}
}永远不会调用onLocationChanged。我将两次更新之间的最短时间设置为1分钟。它不会在1分钟内调用,也不会在位置更改时调用。
发布于 2014-04-22 15:17:34
您必须先请求更新,然后才能通过以下方式获取更新:
LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);此外,请记住将ACCESS_FINE_LOCATION作为权限添加到清单中
https://stackoverflow.com/questions/23212575
复制相似问题