In my android app, i'm playing with user location. Problem is I want to know whether GPS is locked or still it is trying to get i.e, is there flag or some method to know, the moment GPS is locked?
Asked
Active
Viewed 2,867 times
0
-
1I made some code that handles this: http://stackoverflow.com/questions/19365035/location-servise-gps-force-closed/19366773#19366773 – cYrixmorten Dec 19 '13 at 08:26
2 Answers
0
http://developer.android.com/reference/android/location/GpsStatus.html
This might be what you're looking for.

George Daramouskas
- 3,720
- 3
- 22
- 51
0
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
if (location.getProvider().equals("gps")) {
//FROM GPS
if(isSearching){//GPS called first time after Enable
isSearching=false;
}
} else {
//FROM NETWORK
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
isSearching = true;
// GPS IS SEARCHING
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
Raise a flag whenever the user enables the gps. OnLocationChanged is never called until the gps is fixed.

AabidMulani
- 2,325
- 1
- 28
- 47
-
I believe this will give a false positive, as onLocationChanged will get called despite GPS not being ready. At least if using network for location too. – cYrixmorten Dec 19 '13 at 08:28
-
This might help you.http://stackoverflow.com/questions/15453576/android-check-if-gps-is-searching-has-fix-or-is-not-in-use/20812298?noredirect=1#comment31380852_20812298 – Sarweshkumar C R May 14 '14 at 12:52