Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalArgumentException: provider doesn't exist: gps

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);
like image 851
Yugesh Avatar asked Mar 14 '16 07:03

Yugesh


3 Answers

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.

like image 170
Jeff Richards Avatar answered Oct 03 '22 01:10

Jeff Richards


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)

like image 30
Onkar Nene Avatar answered Oct 03 '22 01:10

Onkar Nene


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

like image 44
Longe Tolulope Avatar answered Oct 03 '22 03:10

Longe Tolulope