I'm building an app which shows the user there current address by Toast, using lat long. I'm using Geocoder to convert lat long into address, but the case is, on some devices address is working fine but in some devices its crashes. Then I debug the app on those devices on it crashes, I found that after geocoder line it jumps to catch(Exception), without executing the other lines. So, is there any other ways to get location by lat long.
There is another question with same problem here ,But that did't give much solution so i'm asking it again.
My Geocoder block is
if (mLastLocation != null) {
double latitude = mLastLocation.getLatitude();
double longitude = mLastLocation.getLongitude();
try {
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude,longitude,1);
if (addresses != null && addresses.size() > 0){
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
Toast.makeText(getApplicationContext(), "Your address is: " +address+ " "+city+ " " + state+ "\n" +country+ " "+ postalCode, Toast.LENGTH_LONG).show();
}
}catch (Exception e){
e.printStackTrace();
}