Note that there are some explanatory texts on larger screens.

plurals
  1. POonLocationChanged is not fired in jelly bean
    text
    copied!<p>I have used following code for getting the location. It is working fine in Android 4.0.4 but not in 4.1.1. Googled a lot but not found any solution.Please help me Thanks in advance.</p> <pre><code>mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocListener = new UserLocationListener(getApplicationContext()); if (mLocationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mLocationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 1, 0, mLocListener); } else if (mLocationManager .isProviderEnabled(LocationManager.GPS_PROVIDER)) { mLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 1, 0, mLocListener); } public class UserLocationListener implements LocationListener { Context mContext; String mCurrLocation = null; double latitude, longitude; String locale; public String getLocale() { return locale; } public String getmCurrLocation() { return mCurrLocation; } public double getLatitude() { return latitude; } public double getLongitude() { return longitude; } public UserLocationListener(Context _mContext) { mContext = _mContext; } @Override public void onLocationChanged(Location location) { Geocoder gcd = new Geocoder(mContext, Locale.getDefault()); List&lt;Address&gt; addresses = null; try { addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1); longitude = location.getLongitude(); latitude = location.getLatitude(); locale = Locale.getDefault().getCountry(); if (addresses.size() &gt; 0) { mCurrLocation = formatAddress(addresses.get(0)); } else { Log.e("LocationListener", "Geocoder backend service not present"); } } catch (IOException e) { } catch (NullPointerException e) { } } /** * Formats the Address to a meaningful String representation * * @param address * @return String */ private String formatAddress(Address address) { String addr = ""; StringBuilder sb = new StringBuilder(); if (address.getAddressLine(0) != null) { sb.append(address.getAddressLine(0)); } else if (address.getSubThoroughfare() != null) { sb.append(address.getSubThoroughfare()); } else if (address.getSubThoroughfare() != null) { sb.append(address.getSubThoroughfare()); } else if (address.getThoroughfare() != null) { sb.append(address.getThoroughfare()); } else if (address.getSubLocality() != null) { sb.append(address.getSubLocality() + ","); } else if (address.getPremises() != null) { sb.append(address.getPremises() + ","); } else if (address.getLocality() != null) { sb.append(address.getLocality() + ","); } else if (address.getSubAdminArea() != null) { sb.append(address.getSubAdminArea() + ","); } else if (address.getAdminArea() != null) { sb.append(address.getAdminArea() + ","); } else if (address.getPostalCode() != null) { sb.append(address.getPostalCode() + ","); } else if (address.getCountryName() != null) sb.append(address.getCountryName() + ","); addr = sb.toString(); return addr; } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload