turn on device location android programmatically

Solutions on MaxInterview for turn on device location android programmatically by the best coders in the world

showing results for - "turn on device location android programmatically"
Helga
21 Jan 2019
1    protected void enableLocationSettings() {
2        LocationRequest locationRequest = LocationRequest.create()
3                .setInterval(10 * 1000)
4                .setFastestInterval(2 * 1000)
5                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
6
7        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
8                .addLocationRequest(locationRequest);
9
10        LocationServices
11                .getSettingsClient(requireActivity())
12                .checkLocationSettings(builder.build())
13                .addOnSuccessListener(requireActivity(), (LocationSettingsResponse response) -> {
14                    // startUpdatingLocation(...);
15                })
16                .addOnFailureListener(requireActivity(), ex -> {
17                    if (ex instanceof ResolvableApiException) {
18                        try{
19                            IntentSenderRequest intentSenderRequest = new IntentSenderRequest.Builder(((ResolvableApiException) ex).getResolution()).build();
20                            resolutionForResult.launch(intentSenderRequest);
21                        }catch (Exception exception){
22                            Log.d(TAG, "enableLocationSettings: "+exception);
23                        }
24                    }
25                });
26    }
27
Ilias
19 Jun 2018
1     protected void enableLocationSettings() {
2        LocationRequest locationRequest = LocationRequest.create()
3                .setInterval(10 * 1000)
4                .setFastestInterval(2 * 1000)
5                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
6
7        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
8                .addLocationRequest(locationRequest);
9
10        LocationServices
11                .getSettingsClient(requireActivity())
12                .checkLocationSettings(builder.build())
13                .addOnSuccessListener(requireActivity(), (LocationSettingsResponse response) -> {
14                    // startUpdatingLocation(...);
15                })
16                .addOnFailureListener(requireActivity(), ex -> {
17                    if (ex instanceof ResolvableApiException) {
18                        try{
19                            IntentSenderRequest intentSenderRequest = new IntentSenderRequest.Builder(((ResolvableApiException) ex).getResolution()).build();
20                            resolutionForResult.launch(intentSenderRequest);
21                        }catch (Exception exception){
22                            Log.d(TAG, "enableLocationSettings: "+exception);
23                        }
24                    }
25                });
26    }
27
similar questions