Am using GPS to get the Users Location, In Samsung Galaxy S5(klte) with Android 5.0 shows error like java.lang.IllegalArgumentException: provider doesn't exist: gps
but the device have GPS. Can tell Whats the error Exactly denotes like no GPS or Not able to access the GPS.
Can anyone know help me out to solve this issue.
Error Log
Caused by: java.lang.IllegalArgumentException: provider doesn't exist: gps
at android.os.Parcel.readException(Parcel.java:1544)
at android.os.Parcel.readException(Parcel.java:1493)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:584)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:867)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:459)
at melbourne.webdesign.karmaridedriver.Driver_location_update.onStartCommand(Driver_location_update.java:62)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3259)
... 9 more
Driver_location_update.java:62
denotes below Line
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, listener);
I am experiencing the same thing in my app. In reviewing the crash log I see that the device that it happened on is an RCA Voyager 16GB. Looking at the specs for that device I see that it has NO GPS. So a question for your case is, does the GPS work correctly in other apps for that device?
In my case, I can't actually reproduce the issue cause I don't have a device without a gps but my best bet is to try and safeguard my turning on location updates from that provider.
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, Constants.LOCATION_UPDATE_INTERVAL, 0, this);
}
I think the real answer here is to move over to the FusedLocationProviderApi and then this becomes the api's problem. But sometimes I prefer to just nudge the code a little to make it work rather than get out the ax and start hacking.
Try this -
private Location getMyLocation() {
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// if Location wasn't found
if (myLocation == null) {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String provider = lm.getBestProvider(criteria, true);
// Use the provider to get the last known location
myLocation = lm.getLastKnownLocation(provider);
double lat1 = myLocation.getLatitude();
double lng1 = myLocation.getLongitude();
}
return myLocation;
}
Call this method in onCreate() and use OnMyLocationChangeListener for that activity. It works great for me :)
Note : OnMyLocationChangeListener is Deprecated (please check google documentation)
Network or GPS provider doesn't exist on some devices, so if you start corresponding services, it doesn't work. It's better to check with an if statement like this:
if(locationManager.getAllProviders().contains("network")) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, this);
}
worked perfectly fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With