本文整理匯總了Java中com.google.android.gms.location.LocationSettingsRequest類的典型用法代碼示例。如果您正苦於以下問題:Java LocationSettingsRequest類的具體用法?Java LocationSettingsRequest怎麽用?Java LocationSettingsRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LocationSettingsRequest類屬於com.google.android.gms.location包,在下文中一共展示了LocationSettingsRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: displayLocationSettingsRequest
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
public void displayLocationSettingsRequest(final Activity activity) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
.addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(mAccuracy);
locationRequest.setInterval(mInterval);
locationRequest.setFastestInterval(mInterval / 2);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(false);
final PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new LocationResultCallback(activity));
}
示例2: updateLocation
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private void updateLocation() {
Log.v(TAG, "Trying to update location...");
if (isDelayedUpdate()) Log.v(TAG, "Detected delayed updates.");
else {
if (checkConnection()) {
if (hasPermissions()) {
setRequestingPermissions(true);
LocationSettingsRequest.Builder builder =
new LocationSettingsRequest.Builder().addLocationRequest(
getLocationRequest()).setAlwaysShow(true);
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
builder.build()).setResultCallback(getLocationSettingsResultCallback());
Log.v(TAG, "Settings verification requested.");
} else checkForPermissions();
}
}
}
示例3: onConnected
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
@Override
public void onConnected(Bundle bundle) {
//inicializa list view
adapter=new ArrayAdapter<Location>(this, android.R.layout.simple_list_item_1, data);
setListAdapter(adapter);
//define requisicao para obter localizacao
//objeto define quantos updates serao necessarios
//deadline para desistir se nao conseguir obter location
//intervalo
//otimizacao de energia, caso aplicavel
locationRequest = new LocationRequest()
.setNumUpdates(5)
.setExpirationDuration(60000)
.setInterval(1000)
.setPriority(LocationRequest.PRIORITY_LOW_POWER);
LocationSettingsRequest.Builder b = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(playServices, b.build());
result.setResultCallback(this);
}
示例4: onConnected
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
LocationRequest locationRequest = createLocationRequest();
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
locationSettingsResultPendingResult
.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) {
if (result.getStatus().hasResolution()) {
handleLocationStatusResult(result.getStatus());
} else {
// TODO: faire quelque chose
}
}
}
});
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// la demande des droits est faite ailleurs
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
onLocationChanged(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient));
}
示例5: configureLocationConnection
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private void configureLocationConnection() {
LocationRequest locationRequest = createLocationRequest();
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> locationSettingsResultPendingResult = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
locationSettingsResultPendingResult
.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
if (LocationSettingsStatusCodes.SUCCESS != result.getStatus().getStatusCode()) {
Intent localIntent = new Intent(Constants.GOOGLE_API).putExtra(Constants.GOOGLE_API_LOCATION_RESULT, result.getStatus());
LocalBroadcastManager.getInstance(ParcoursService.this).sendBroadcast(localIntent);
}
}
});
// noinspection MissingPermission : permissions dans le manifest
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
}
示例6: setupGeoLocation
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private void setupGeoLocation() {
Log.d(TAG, "setupGeoLocation()");
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10 * 60 * 1000); // 10 minutes, in milliseconds
mLocationRequest.setFastestInterval(60 * 1000); // 60 second, in milliseconds
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // We wanto to center the Player on his actual position
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true); // "This app wants to change your device settings for GPS location"
mLocationSettingsRequest = builder.build();
}
示例7: onConnected
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
/**
* GoogleApiClient interfaces
*/
@Override
public void onConnected(@Nullable Bundle bundle) {
final LocationRequest locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_LOW_POWER);
final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest)
.setNeedBle(true);
final PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
try {
status.startResolutionForResult(getCurrentActivity(), NEAR_LOCATION_SETTINGS_CODE);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
});
}
示例8: getCurrentLocation
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
public Observable<Location> getCurrentLocation() {
if (ActivityCompat.checkSelfPermission(activity,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return Observable.error(new SecurityException("No location permission granted"));
}
LocationRequest locationRequest = LocationRequest.create().setInterval(200).setNumUpdates(1).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
return locationProvider.checkLocationSettings(new LocationSettingsRequest.Builder().setAlwaysShow(true).addLocationRequest(locationRequest).build()).flatMap(locationSettingsResult -> {
if (locationSettingsResult.getStatus().isSuccess()) {
return locationProvider.getUpdatedLocation(locationRequest)
.doOnNext(location -> {
Timber.d("Location", location.toString());
})
.flatMap(locations -> getLocationFromLatLng(locations.getLatitude(), locations.getLongitude()));
} else {
try {
fragment.startIntentSenderForResult(locationSettingsResult.getStatus().getResolution().getIntentSender(), locationRequestCode, null, 0, 0, 0, null);
} catch (IntentSender.SendIntentException e) {
return Observable.error(e);
}
return Observable.error(new RuntimeException("Location not enabled"));
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
示例9: initService
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private void initService() {
setNotification();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(NavigationService.this, getString(R.string.erreur_autorisation), Toast.LENGTH_SHORT).show();
quit();
return;
}
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(2000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
builder.build());
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this);
}
示例10: onConnected
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(2000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
builder.build());
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
}
});
}
示例11: onConnected
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(2000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient,
builder.build());
if (isExploreByTouchEnabled) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
((CheckBox) findViewById(R.id.bus_checkbox)).setChecked(sharedPref.getBoolean(getString(R.string.pref_bus_key), false));
checkSavedItinerary(); //Because for other, the check is done onMapReady
Intent intent = new Intent(this, MyAddressService.class);
startService(intent);
} else {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
}
示例12: checkLocationSettings
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
/**
* Observable that can be used to check settings state for given location request.
*
* @param locationRequest location request
* @return observable that emits check result of location settings
* @see com.google.android.gms.location.SettingsApi
*/
public Observable<LocationSettingsResult> checkLocationSettings(final LocationSettingsRequest locationRequest) {
return getGoogleApiClientObservable(LocationServices.API)
.flatMap(new Func1<GoogleApiClient, Observable<LocationSettingsResult>>() {
@Override
public Observable<LocationSettingsResult> call(GoogleApiClient googleApiClient) {
return fromPendingResult(LocationServices.SettingsApi.checkLocationSettings(googleApiClient, locationRequest));
}
});
}
示例13: getLocationSettingsStatus
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private Status getLocationSettingsStatus(GoogleApiClient googleApiClient) {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.setAlwaysShow(true);
builder.addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
return result.await().getStatus();
}
示例14: checkLocationEnabled
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
private void checkLocationEnabled() {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(_locationRequest);
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(_client,
builder.build());
result.setResultCallback(new MyLocationSettingsCallback());
}
示例15: ensure
import com.google.android.gms.location.LocationSettingsRequest; //導入依賴的package包/類
@NonNull
public Single<Boolean> ensure(@NonNull LocationSettingsRequest request) {
return rxLocationProvider.checkLocationSettings(request).toSingle()
.flatMap(new Func1<LocationSettingsResult, Single<Boolean>>() {
@Override
public Single<Boolean> call(LocationSettingsResult result) {
Status status = result.getStatus();
if (status.hasResolution()) {
return resolutionFragment.startResolutionForResult(status.getResolution());
}
return Single.just(status.isSuccess());
}
});
}