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


Java LocationServices.getSettingsClient方法代碼示例

本文整理匯總了Java中com.google.android.gms.location.LocationServices.getSettingsClient方法的典型用法代碼示例。如果您正苦於以下問題:Java LocationServices.getSettingsClient方法的具體用法?Java LocationServices.getSettingsClient怎麽用?Java LocationServices.getSettingsClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.location.LocationServices的用法示例。


在下文中一共展示了LocationServices.getSettingsClient方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.title_settings);

    // start location services, including permissions checks, etc.
    context = this;
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    useGPS = preferences.getBoolean("use_device_location", false);
    locUpdates = false;
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
    mSettingsClient = LocationServices.getSettingsClient(context);
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();
    settingsFragment = (SettingsFragment) getFragmentManager().findFragmentById(R.id.fragmentSettings);
}
 
開發者ID:MTBehnke,項目名稱:NightSkyGuide,代碼行數:21,代碼來源:SettingsActivity.java

示例2: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // set default values in the app's SharedPreferences if never changed
    // note - does not reset preferences back to default values if previously changed
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // start location services, including permissions checks, etc.
    context = this;
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //preferences.edit().remove("multi_pref_constellation").apply();   //used to clear existing preference if required
    useGPS = preferences.getBoolean("use_device_location", false);
    locUpdates = false;
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
    mSettingsClient = LocationServices.getSettingsClient(context);
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();

    if (savedInstanceState == null) {
        // create DSObjectsFragment
        dsObjectsFragment = new DSObjectsFragment();

        // add the fragment to the FrameLayout
        FragmentTransaction transaction =
                getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragmentContainer, dsObjectsFragment);
        transaction.commit();  // display DSObjectsFragment
    }
}
 
開發者ID:MTBehnke,項目名稱:NightSkyGuide,代碼行數:35,代碼來源:MainActivity.java

示例3: setUpLocationRequest

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public void setUpLocationRequest(OnSuccessListener<LocationSettingsResponse> successListener,
    OnFailureListener onFailureListener) {
  LocationRequest locationRequest = getLocationRequest();
  LocationSettingsRequest.Builder builder =
      new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
  SettingsClient settingsClient = LocationServices.getSettingsClient(context);
  Task<LocationSettingsResponse> locationSettingsResponseTask =
      settingsClient.checkLocationSettings(builder.build());

  locationSettingsResponseTask.addOnSuccessListener(successListener);

  locationSettingsResponseTask.addOnFailureListener(onFailureListener);
}
 
開發者ID:Arjun-sna,項目名稱:LocationAware,代碼行數:14,代碼來源:LocationProvider.java

示例4: setupLocationService

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
private void setupLocationService() {
    Log.v(TAG, "Setting up location service");
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(getLocationRequest());
    SettingsClient client = LocationServices.getSettingsClient(activity);
    Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());

    task.addOnSuccessListener(activity, new OnSuccessListener<LocationSettingsResponse>() {
        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            Log.v(TAG, "Location settings satisfied");
        }
    });

    task.addOnFailureListener(activity, new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            int statusCode = ((ApiException) e).getStatusCode();
            switch (statusCode) {
                case CommonStatusCodes.RESOLUTION_REQUIRED:
                    Log.w(TAG, "Location settings not satisfied, attempting resolution intent");
                    try {
                        ResolvableApiException resolvable = (ResolvableApiException) e;
                        resolvable.startResolutionForResult(activity, REQUEST_CODE_LOCATION_SETTINGS);
                    } catch (IntentSender.SendIntentException sendIntentException) {
                        Log.e(TAG, "Unable to start resolution intent");
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.w(TAG, "Location settings not satisfied and can't be changed");
                    break;
            }
        }
    });
}
 
開發者ID:neXenio,項目名稱:BLE-Indoor-Positioning,代碼行數:36,代碼來源:AndroidLocationProvider.java

示例5: startLocationService

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
/**
 * Method to check for the location settings of the device,
 * if it doesn't fit the current requirement of the app
 * open the settings for user to change them, if the settings are OK, starts the TimeService.
 */

@Override
public void startLocationService() {
    LocationRequest request = new LocationRequest()
            .setFastestInterval(1500)
            .setInterval(3000)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder settingsRequest = new LocationSettingsRequest.Builder();
    settingsRequest.addLocationRequest(request);

    SettingsClient client = LocationServices.getSettingsClient(getActivity());
    Task<LocationSettingsResponse> responseTask = client.checkLocationSettings
            (settingsRequest.build());

    responseTask.addOnSuccessListener(getActivity(), locationSettingsResponse ->
            locationScheduler());

    responseTask.addOnFailureListener(getActivity(), e -> {
        int statusCode = ((ApiException) e).getStatusCode();

        switch (statusCode){
            case CommonStatusCodes.RESOLUTION_REQUIRED:
                try {
                    ResolvableApiException apiException = ((ResolvableApiException)e);
                    apiException.startResolutionForResult(getActivity(), permissionCode);
                    Log.d(TAG, "Dialog displayed");
                }catch (IntentSender.SendIntentException sendIntentException){
                    Log.d(TAG, "Error displaying dialogBox", sendIntentException);
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                Log.d(TAG, "Unable to turn on location service", e);

        }
    });
}
 
開發者ID:aumarbello,項目名稱:WalkGraph,代碼行數:43,代碼來源:MapFragmentImpl.java

示例6: onCreate

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    lsf = new LoadingScreenFragment();
    hf = new FirstHintFragment();

    SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
            .add(R.id.hint_cont, lsf)
            .show(lsf)
            .commit();


    mRequestingLocationUpdates = false;
    mLastUpdateTime = "";

    // Update values using data stored in the Bundle.
    updateValuesFromBundle(savedInstanceState);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mSettingsClient = LocationServices.getSettingsClient(this);

    // Kick off the process of building the LocationCallback, LocationRequest, and
    // LocationSettingsRequest objects.
    createLocationCallback();
    createLocationRequest();
    buildLocationSettingsRequest();

    isLocationEnabled = false;

    mLocationPermissionGranted = checkPermissions();
    if(!mLocationPermissionGranted) {
        requestPermissions();
    } else {
        startLocationUpdates();
    }

    LanguageManager.languageManagement(this);

    keepScreenOn();
}
 
開發者ID:Augugrumi,項目名稱:SpaceRace,代碼行數:49,代碼來源:MapActivity.java

示例7: RxSettingsClient

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
public RxSettingsClient(@NonNull Context context) {
    checkNotNull(context, "context == null");
    this.client = LocationServices.getSettingsClient(context);
}
 
開發者ID:niqo01,項目名稱:RxTask,代碼行數:5,代碼來源:RxSettingsClient.java

示例8: init

import com.google.android.gms.location.LocationServices; //導入方法依賴的package包/類
private void init() {
    Log.d(TAG, "init");

    isActivityForeground = true;

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    if (getSupportActionBar() != null)
        getSupportActionBar().setTitle(R.string.locations);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    mSettingsClient = LocationServices.getSettingsClient(this);

    createLocationCallBack();
}
 
開發者ID:farukydnn,項目名稱:WeatherPlus,代碼行數:16,代碼來源:MainActivity.java


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