I am new in Android. I develop one application which have to display Current Location name. I tried to use Geocoder class. But it seems in some phone display properly Location but in some it is displaying any location and getting null.
My code is here,
Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());
List<Address> listAddresses = null;
try {
listAddresses = geocoder.getFromLocation(gps.getLatitude(), gps.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
}
if (null != listAddresses && listAddresses.size() > 0) {
Location = "";
for (int i = 0; i < 4; i++) {
if (listAddresses.get(0).getAddressLine(i) != null) {
Location += listAddresses.get(0).getAddressLine(i) + ",";
}
}
Log.e("Location", Location);
}
My Manifest class,
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
I can't understand what is the problem ? Is it depend on different devices ? Or any other reason ?