Google在其blog post中描述了一個單觸設置對話框,要求用戶打開其位置(讓用戶打開位置而不將其發送到手機的設置)。 我只是找不到合適的方法/方法在他們的API文檔中做到這一點。Google Play Services 7.0設置對話框
任何人都已經使用這個,並可以給出解釋?
Google在其blog post中描述了一個單觸設置對話框,要求用戶打開其位置(讓用戶打開位置而不將其發送到手機的設置)。 我只是找不到合適的方法/方法在他們的API文檔中做到這一點。Google Play Services 7.0設置對話框
任何人都已經使用這個,並可以給出解釋?
更具體的,相關的代碼如下
class MainActivity extends Activity implements ResultCallback<LocationSettingsResult> {
protected void checkLocationSettings() {
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mGoogleApiClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
}
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.i(TAG, "All location settings are satisfied.");
startLocationUpdates();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" +
"upgrade location settings ");
try {
// Show the dialog by calling startResolutionForResult(), and check the result
// in onActivityResult().
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " +
"not created.");
break;
}
}
}
// This code is from https://github.com/googlesamples/android-play-location/blob/master/LocationSettings/app/src/main/java/com/google/android/gms/location/sample/locationsettings/MainActivity.java
在LocationSettingsStatusCodes#RESOLUTION_REQUIRED的結果回調,Status.startResolutionForResult會做的伎倆。
我一直在等待這個選項,因爲他們把它說出來.... http://stackoverflow.com/questions/28759454/enabling-location-with-mode-high-accuracy-or-battery-saving-沒有用戶,需要 – user2450263