當前位置: 首頁>>代碼示例>>Java>>正文


Java LocationSettingsRequest類代碼示例

本文整理匯總了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));
}
 
開發者ID:philiWeitz,項目名稱:react-native-location-switch,代碼行數:19,代碼來源:LocationSwitch.java

示例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();
        }
    }
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:19,代碼來源:LocationAdapter.java

示例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);
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:24,代碼來源:FusedLocationMapActivity.java

示例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));
}
 
開發者ID:ANFR-France,項目名稱:proto-collecte,代碼行數:26,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:ANFR-France,項目名稱:proto-collecte,代碼行數:18,代碼來源:ParcoursService.java

示例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();
}
 
開發者ID:stefanonicolai,項目名稱:AstronomyTourPadova,代碼行數:21,代碼來源:GmapFragment.java

示例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();
        }
      }
    }
  });
}
 
開發者ID:nearit,項目名稱:react-native-connectivity-status,代碼行數:29,代碼來源:RNConnectivityStatusModule.java

示例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());
}
 
開發者ID:lvanyal,項目名稱:directly,代碼行數:26,代碼來源:LocationRepositoryImpl.java

示例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);


}
 
開發者ID:snigle,項目名稱:corsaire,代碼行數:26,代碼來源:NavigationService.java

示例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) {

        }
    });
}
 
開發者ID:snigle,項目名稱:corsaire,代碼行數:21,代碼來源:MyAddressService.java

示例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);
    }


}
 
開發者ID:snigle,項目名稱:corsaire,代碼行數:26,代碼來源:MainActivity.java

示例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));
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:ReactiveLocationProvider.java

示例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();
}
 
開發者ID:titanium-codes,項目名稱:LocGetter,代碼行數:8,代碼來源:LocationGetterImpl.java

示例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());
}
 
開發者ID:Gustash,項目名稱:flutter_geolocation,代碼行數:9,代碼來源:GpsCoordinatesPlugin.java

示例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());
        }
      });
}
 
開發者ID:JetradarMobile,項目名稱:android-rxlocationsettings,代碼行數:15,代碼來源:RxLocationSettings.java


注:本文中的com.google.android.gms.location.LocationSettingsRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。