![](/img/trans.png)
[英]Stop location updates by using the last google play services api location
[英]Using Google Play Services Location API to get listen for location services updates
我正在嘗試使用Google Play服務的位置API(com.google.android.gms.location)來監聽位置服務的更新(即用戶在系統設置中打開/關閉位置)。
我知道我可以查詢這個信息:
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResponse;
import com.google.android.gms.location.SettingsClient;
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
// ...
SettingsClient client = LocationServices.getSettingsClient(this);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
我也知道我可以使用android SDK來監聽 :
import android.location.LocationManager;
import android.provider.Settings
private BroadcastReceiver locationServicesBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.getAction())) {
int locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
boolean isEnabled = locationMode != Settings.Secure.LOCATION_MODE_OFF;
}
}
};
但我可以用播放服務API 和聽呢?
Google Play服務較新,並且在管理此類請求方面提供了更好的功能; 他們更實惠。 它們處理內存,電池使用情況和連接的能力遠遠優於舊的android.location庫。 這是Google棄用它的地方
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.