0
My code was working, I was getting latitude and longitude normally, but it stopped and I’m not getting the location anymore. It only falls on the condition that it was not possible to pick up the location
private void foto(int actionCode) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final boolean GPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (GPSEnabled) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
switch (actionCode) {
case ACTION_TAKE_PHOTO_B:
File f = null;
try {
f = setUpPhotoFile();
mCurrentPhotoPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
} else {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
if (location != null) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
else {
Toast.makeText(Menu.this, "Não foi possivel obter sua localização" +
"", Toast.LENGTH_SHORT).show();
return;
}
} catch (IOException e) {
e.printStackTrace();
f = null;
mCurrentPhotoPath = null;
}
break;
default:
break;
} // switch
Puts a
Log.d
within this if:if (ActivityCompat.checkSelfPermission(this,
 android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.i("MINHA_TAG", "Sem permissão"); }
– Guilherme Nascimento
I did, but it doesn’t go through that log
– Juliano Morche
getLastKnownLocation actually returns the last registered position, maybe he could not register his last position, open google maps ask to locate you and then open your app just to test.
– Guilherme Nascimento
I did it and it didn’t work, but I have a GPS Status app, when I open it and it picks up location, I open my app, but when saved in the bank is only in the same location, no matter where I go.
– Juliano Morche
But why is the question bank or GPS? Okay, let’s split, first look at this
https://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener)
(android.com link breaks, copies and pastes in the browser)– Guilherme Nascimento