“Activer l'emplacement de l'appareil Android par programme” Réponses codées

Activer l'emplacement de l'appareil Android par programme

     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);
                        }
                    }
                });
    }
Frail Flatworm

Activer l'emplacement de l'appareil Android par programme

    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);
                        }
                    }
                });
    }
Frail Flatworm

Réponses similaires à “Activer l'emplacement de l'appareil Android par programme”

Questions similaires à “Activer l'emplacement de l'appareil Android par programme”

Plus de réponses similaires à “Activer l'emplacement de l'appareil Android par programme” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code