0
我正在開發一個應用程序需要檢索用戶位置的時間段。我在活動中使用了LocationListener接口,並且它運行良好,但是當我在我的android服務中實現它時,它不會被調用。這裏的onCreate方法:onLocationUpdate不是在服務調用
public void onCreate() {
super.onCreate();
turned= true;
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
locationManager = (LocationManager) this
.getSystemService(LOCATION_SERVICE);
String provider = locationManager.getBestProvider(criteria, true);
locationManager
.requestLocationUpdates(provider, 0, 0, this); ...}
我真的很感謝所有幫助,服務優良似乎因爲我送麪包和它們被髮送,但onLocationUpdate不會被調用。
你確定它實際上有一個GPS鎖?這可能需要一段時間。參考:http://stackoverflow.com/questions/5337333/android-onlocationupdate-not-called-with-gps-provider – 2013-04-24 17:33:55
我打電話給onStartCommand()而不是OnCreate(),它適用於我。您可能想嘗試一下。 – 2013-04-24 17:36:10
非常感謝Shobhit Puri,你的回答解決了我的問題。 – user1998791 2013-04-24 19:26:59