我尝试通过网络提供商检索服务中的位置更新,但更新没有执行。我的代码如下所示:
public class TimeService extends Service{
LocationManager lm;
LocationListener ll = new LocationListener()
{
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longtitude = location.getLongitude();
Intent inte =new Intent( TimeService.this, myAppWidgetProvider.class);
inte.setAction("action_location");
inte.putExtra("lat", latitude);
inte.putExtra("long", longtitude);
PendingIntent pinte = PendingIntent.getBroadcast(TimeService.this, 0, inte, 0);
try {
pinte.send();
} catch (CanceledException e) {
// TODO Auto-generated catch block
Log.d("sendPIException", ":-(");
}
Log.d("locReceived", "onLochanged");
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
};
在 onLocationChanged 中记录“locReceived”没有出现我 logcat 以下代码也负责我的服务中的位置:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.registerReceiver(br, new IntentFilter(Intent.ACTION_TIME_TICK));
lm =(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
return super.onStartCommand(intent, flags, startId);
}
我的代码有什么问题?