I'm having the following error on android 21 and above.
I'm having the following error, and there is no restriction on manufacturer or model for the error.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] android.content.pm.PackageManager.getPackagesForUid(int)' on a null object reference
at android.os.Parcel.readException(Parcel.java:1605)
at android.os.Parcel.readException(Parcel.java:1552)
at android.location.ILocationManager$Stub$Proxy.getLastLocation(ILocationManager.java:717)
at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1200)
at [...]
The call that triggers the error is either one bellow:
mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
I check beforehand if the mLocationManager is not null or if I have the necessary permissions. It work on most cases but I do have some crashing occurrences.
Does anyone knows what can be done to avoid it, or if there is any way to detect that it will happen so I don't request the location?
Thanks for your attention,