简体   繁体   中英

Can't get location on Samsung Galaxy Tab 2 & Note

I use this code to get the location:

final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        final Criteria locationCritera = new Criteria();
        locationCritera.setAccuracy(Criteria.ACCURACY_COARSE);
        locationCritera.setAltitudeRequired(false);
        locationCritera.setBearingRequired(false);
        locationCritera.setCostAllowed(true);
        locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT);

        final String providerName = locationManager.getBestProvider(locationCritera, true);

        if (providerName != null && locationManager.isProviderEnabled(providerName)) {
            locationManager.requestLocationUpdates(providerName, 20000, 100, this);
        } else {
            Toast.makeText(this, "GPS turned off!", Toast.LENGTH_LONG).show();
            final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

Both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions are defined in manifest.

Both network & GPS are turned on, but I'm getting only onProviderEnabled called with param "network" (once). But the same code works fine on 4.0 emulator & Onda 4.1 Tab. Why?

I have a GPS example. Maybe you can use it as reference: Example is here :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM