androidgpsgeolocationlocationmanager

GPS provider not return my current location android


I am trying to get user current location but my onLocationChanged method never get called.I have added permissions in Manifest.xml also,But onLocationChange method never get called. I have open GPS of my device and try it on two different mobile but not working. Below is my code -

public class LocationAwareActivity extends Activity implements
         LocationListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LocationManager locationManager = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 1000, 1, this);

}


@Override
public void onLocationChanged(Location location) {
    Toast.makeText(this, "Current onLocationChanged : "+location.getLatitude()+" , "+location.getLongitude(), Toast.LENGTH_SHORT).show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    Toast.makeText(this, "onStatusChanged", Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderEnabled(String provider) {
    Toast.makeText(this, "onProviderEnabled", Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderDisabled(String provider) {
    Toast.makeText(this, "onProviderDisabled", Toast.LENGTH_SHORT).show();
}

and below is code of manifest.xml -

 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

TIA


Solution

  • Use the new Fused location provider for fetching the location.
    
    The Fused Location Provider intelligently manages the underlying location technology and gives you the best location according to your needs.
    
    Refer below links:
    
    1. https://developer.android.com/google/play-services/location.html
    2. http://javapapers.com/android/android-location-fused-provider/
    3. http://www.kpbird.com/2013/06/fused-location-provider-example.html