Tuesday, 13 August 2013

Get current location android force close

Get current location android force close

I put this code in onCreate method in API 17 targeted app
LocationManager lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
// connect to the GPS location service
Location loc =
lm.getLastKnownLocation(lm.NETWORK_PROVIDER);
Toast.makeText(MainActivity.this, "Latitude ->
"+Double.toString(loc.getLatitude())
+" Longitude is ->
"+Double.toString(loc.getLongitude()),
Toast.LENGTH_LONG).show();
but it always gives me force close
Internet,FineLocation permissions are allowed so what`s the problem?

No comments:

Post a Comment