Search
 
SCRIPT & CODE EXAMPLE
 

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);
                        }
                    }
                });
    }
Comment

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);
                        }
                    }
                });
    }
Comment

PREVIOUS NEXT
Code Example
Java :: java load config file 
Java :: Error: Unable to export or encrypt the private key java.lang.NullPointerException 
Java :: online java http request demo 
Java :: import java.util.* 
Java :: The JCheckBox and JComboBox classes belong to which package? 
Java :: convert code python to java 
Java :: java scan next into array 
Java :: discord jda await msg 
Java :: comment initialiser un tableau de char en java 2d array 
Java :: multi threading callable 
Java :: how to read space separated characters in java 
Java :: substring in java 
Java :: how to change default size kafka 
Java :: how to create a udp protocol for transfer a big quantity of files java 
Java :: Make device not run on emulator or rooted device 
Java :: Caused by: java.lang.IllegalStateException: stream has already been operated upon or closed 
Java :: how to check if rs next is null 
Java :: Java (HotSpot 12) sample 
Java :: younger brother of java 
Java :: hadoop fs get size of directory java 
Java :: java ordenar los valores de un array de menor a mayor 
Java :: sphere 
Java :: detecting battery charging android 
Java :: java operator 
Java :: Double And Char In Java 
Java :: does java recognize on a txt file 
Java :: java list to collections 
Java :: Repeat execution of function infini android studio 
Java :: JAVA Display numbers from 1 to 5 
Java :: como llamar a un metodo static en java 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =