2013-09-23 5 views
0

Я пытаюсь получить обновления местоположения в службе поставщиком сети, но обновления не выполняются, т. Мой код выглядит следующим образом:Получение обновлений местоположения в службе на Android

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 

    } 

}; 

журнала «locReceived» в onLocationChanged не появляется я 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); 
    } 

Что плохого в моем коде?

+0

проверить надлежащее разрешение на манифест. – johnny

+0

У меня есть access_coarse_location, access_fine_location и разрешения для Интернета, и я также объявил службу в манифесте. – user2511941

+0

проверить этот, http://stackoverflow.com/questions/6694391/android-get-current-location-of-user-without-using-gps-or-internet – johnny

ответ

0
Criteria criteria = new Criteria(); 

String provider = lm.getBestProvider(criteria, false); 
Location location = lm.getLastKnownLocation(provider); 

lm.requestLocationUpdates(provider, 0, 0, ll); 

if (location == null) { 
    Log.e("Impl", "Location not available"); 
} 
+0

тоже не работает – user2511941

+0

, так что вы даже не входите в 'onLocationChanged' правильно? –

+0

да, именно эта проблема у меня есть – user2511941

Смежные вопросы