我正在開發一個應用程序,該應用程序在啓動時獲取用戶位置。我正在使用Smart Location Library來獲取位置和反向地理編碼。但主要問題在於即使在應用程序關閉後,GPS仍會顯示在通知中。我檢查了堆棧跟蹤,但沒有發現任何泄露的窗口異常。 我使用此代碼來獲取我的位置..Android Smart Location Library在應用程序關閉後總是連接到GPS
private void getMyLocation(){
final long mLocTrackingInterval = 1000000 * 5; // 5 sec
float trackingDistance = 1000 * 10;
LocationAccuracy trackingAccuracy = LocationAccuracy.HIGH;
LocationParams.Builder builder = new LocationParams.Builder()
.setAccuracy(trackingAccuracy)
.setDistance(trackingDistance)
.setInterval(mLocTrackingInterval);
SmartLocation.with(mContext)
.location(provider)
// .continuous()
.oneFix()
.config(builder.build())
.start(this);
}
@Override
public void onLocationUpdated(Location location) {
SmartLocation.with(mContext).geocoding()
.reverse(location,new OnReverseGeocodingListener() {
@Override
public void onAddressResolved(Location location, List<Address> results) {
if (results.size() > 0) {
mAddressList=results;
mLocation=location;
tvLocation.setText(results.get(0).getAddressLine(0)+"\n"+results.get(0).getAddressLine(1));
}
}
});
}
和主actvity的onStop()
方法..
@Override
protected void onStop() {
super.onStop();
SmartLocation.with(mContext).location(provider).stop();
SmartLocation.with(mContext).geocoding().stop();
}
編輯
我使用這個povider。我也試過其他提供者。但仍然是相同的結果。
private LocationGooglePlayServicesWithFallbackProvider provider=new LocationGooglePlayServicesWithFallbackProvider(mContext);
我試了很多,但無法弄清楚是什麼實際問題。任何幫助,將不勝感激。謝謝
您使用的是什麼'provider'? – azizbekian
@azizbekian我使用'LocationGooglePlayServicesWithFallbackProvider'也嘗試過其他提供者 –
使用SmartLocation.with(context).location()。stop();停止位置監聽。 –