Android GPS ON/OFF

missy72

Bekanntes Mitglied
Hi, ist sicher ganz simpel. Aber mit welcher Methode frage ich ab, ob das GPS an oder aus geschaltet ist.
Irgendwie suche ich schon wieder viel zu lange.
Zur Zeit erkenne ich das nur, wenn meine location ein "null" zurückgibt.


Java:
    @SuppressLint("MissingPermission")
    private void updateLocation() {
        FusedLocationProviderClient fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
        fusedLocationProviderClient.getLastLocation().addOnSuccessListener(this::onLocationReceived);
    }

    private void onLocationReceived(Location location) {
        if (location == null) {
            textView.setText("Bitte GPS einschalten");
            return;
        }
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        textView.setText("" + latitude + " | " + longitude);
    }

PS: Es geht nicht um die Berechtigung.
 

missy72

Bekanntes Mitglied
Hab es doch noch raus gefunden.
Code:
        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        List<String> providers = locationManager.getProviders(true);
[passive, network, fused, gps]
 
Zuletzt bearbeitet:

Neue Themen


Oben