Not receiving location updates with LocationListener
3119 1 2019-2-26
Uploading and Loding Picture ...(0/1)
o(^-^)o
djiuser_4ImXhuMHoWpz
lvl.1

Finland
Offline


I'm not receiving any location updates with the following code. Any ideas why? It works on another tablet.

There are two providers, "passive" and "gps" (why not "network" even though WLAN is connected?). Last known location is also null.

Crystal Sky has Android 5.1.1 so requesting permission at runtime is not required. I have declared INTERNET, ACCESS_NETWORK_STATE, ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions in the manifest file.


public class MainActivity extends AppCompatActivity implements LocationListener {

    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
        Log.d(TAG, "Providers: " + locationManager.getProviders(true));
        Location loc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
        Log.d(TAG, loc == null ? "no location" : loc.toString());
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this);
    }

    public void onLocationChanged(Location location) {
        Log.d(TAG, "location changed");
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

}

2019-2-26
Use props
djiuser_4ImXhuMHoWpz
lvl.1

Finland
Offline

Never mind, Crystal Sky's GPS didn't work indoors.
2019-3-26
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules