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


Java LocationSettingsRequest.Builder方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: startLocationService

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的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

示例8: 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

示例9: setUpLocationRequest

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的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

示例10: configureLocationConnection

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的package包/類
private void configureLocationConnection() {
        LocationRequest locationRequest = createLocationRequest();
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
        if (collecteActiverPref) {
            com.google.android.gms.common.api.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(CollecteService.this).sendBroadcast(localIntent);
                            }
                        }
                    });
            // noinspection MissingPermission : permissions dans le manifest
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
            //noinspection MissingPermission
//            mLocationManager.addNmeaListener(new GpsStatus.NmeaListener() {
//                @Override
//                public void onNmeaReceived(long l, String s) {
//                    boolean a = false;
//                }
//            });
        } else {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
        }
    }
 
開發者ID:ANFR-France,項目名稱:proto-collecte,代碼行數:29,代碼來源:CollecteService.java

示例11: onConnected

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
    locationRequest=LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30*1000);
    locationRequest.setFastestInterval(5*1000);

    LocationSettingsRequest.Builder builder=new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);

    locationSettingsResultPendingResult=LocationServices.SettingsApi
            .checkLocationSettings(mGoogleApiClient,builder.build());
    locationSettingsResultPendingResult.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {

            final Status status=locationSettingsResult.getStatus();
            final LocationSettingsStates states=locationSettingsResult.getLocationSettingsStates();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    //All location settings are satisfied. The client can initialize location requests here
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    //Location settings are not satisfied but could be fixed by showing user a dialog
                    try {
                        status.startResolutionForResult(Gps4Activity.this,REQUEST_LOCATION);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    //Location settings are not satisfied and we have no way to fix the settings
                    //so we cannot show the dialog
                    break;
            }
        }
    });
}
 
開發者ID:Pritom14,項目名稱:Gps,代碼行數:40,代碼來源:Gps4Activity.java

示例12: onCreate

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的package包/類
@Override
public void onCreate() {
    Log.d(TAG, "onCreate");
    googleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();
    googleApiClient.connect();
    
    createLocationRequest("highest");
    
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(locationRequest);
    builder.setAlwaysShow(true); // "This app wants to change your device settings for GPS location"
    locationSettingsRequest = builder.build();
    
    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    
    currentNotificationTitle = getResources().getString(R.string.app_name);
    currentNotificationText = getResources().getString(R.string.notification_desc);
    
    // Handling interaction with WiFi
    wifiConnected = Utils.isWifiConnected(getApplicationContext());
    
    // Listening to Network changes (WiFi mostly)
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("android.net.wifi.WIFI_STATUS_CHANGED");
    intentFilter.addAction("android.net.wifi.STATUS_CHANGE");
    
    registerReceiver(AtNetworkReceiver, intentFilter);
}
 
開發者ID:stefanonicolai,項目名稱:AstronomyTourPadova,代碼行數:36,代碼來源:LocationService.java

示例13: setupLocationService

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的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

示例14: isGpsOn

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的package包/類
/**
 * Method to check if GPS is on or not
 */
private void isGpsOn() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);

    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();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    getCurrentLocationAddress();
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        status.startResolutionForResult(
                                MapsActivity.this,
                                REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "Exception : " + e);
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.e(TAG, "Location settings are not satisfied.");
                    break;
            }
        }
    });

}
 
開發者ID:pmathew92,項目名稱:MapsWithPlacesAutoComplete,代碼行數:35,代碼來源:MapsActivity.java

示例15: locationSettingsRequest

import com.google.android.gms.location.LocationSettingsRequest; //導入方法依賴的package包/類
private void locationSettingsRequest(Context context) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(10000);
    locationRequest.setFastestInterval(10000/2);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);

    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
            final Status status = locationSettingsResult.getStatus();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    System.out.println("ALL LOCATION SETTINGS ARE SATISFIED");
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        status.startResolutionForResult(getActivity(), 213);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    System.out.println("STUFF");
                    break;
            }
        }
    });
}
 
開發者ID:STUDIO-apps,項目名稱:GeoShare_Android,代碼行數:37,代碼來源:MapsFragment.java


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