Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

turn on device location android programmatically

     protected void enableLocationSettings() {
        LocationRequest locationRequest = LocationRequest.create()
                .setInterval(10 * 1000)
                .setFastestInterval(2 * 1000)
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

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

        LocationServices
                .getSettingsClient(requireActivity())
                .checkLocationSettings(builder.build())
                .addOnSuccessListener(requireActivity(), (LocationSettingsResponse response) -> {
                    // startUpdatingLocation(...);
                })
                .addOnFailureListener(requireActivity(), ex -> {
                    if (ex instanceof ResolvableApiException) {
                        try{
                            IntentSenderRequest intentSenderRequest = new IntentSenderRequest.Builder(((ResolvableApiException) ex).getResolution()).build();
                            resolutionForResult.launch(intentSenderRequest);
                        }catch (Exception exception){
                            Log.d(TAG, "enableLocationSettings: "+exception);
                        }
                    }
                });
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #turn #device #location #android #programmatically
ADD COMMENT
Topic
Name
3+4 =