How to stop Android GPS using "Mobile data"
- by prepbgg
My app requests location updates with "minTime" set to 2 seconds. When "Mobile data" is switched on (in the phone's settings) and GPS is enabled the app uses "mobile data" at between 5 and 10 megabytes per hour. This is recorded in the ICS "Data usage" screen as usage by "Android OS".
In an attempt to prevent this I have unticked Settings-"Location services"-"Google's location service". Does this refer to Assisted GPS, or is it something more than that? Whatever it is, it seems to make no difference to my app's internet access.
As further confirmation that it is the GPS usage by my app that is causing the mobile data access I have observed that the internet data activity indicator on the status bar shows activity when and only when the GPS indicator is present.
The only way to prevent this mobile data usage seems to be to switch "Mobile data" off, and GPS accuracy seems to be almost as good without the support of mobile data. However, it is obviously unsatisfactory to have to switch mobile data off.
The only permissions in the Manifest are "android.permission.ACCESS_FINE_LOCATION" (and "android.permission.WRITE_EXTERNAL_STORAGE"), so the app has no explicit permission to use internet data.
The LocationManager code is
`
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setSpeedRequired(false);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(true);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
bestProvider = lm.getBestProvider(criteria, true);
if (bestProvider != null) {
lm.requestLocationUpdates(bestProvider, gpsMinTime, gpsMinDistance, this);
`
The reference for LocationManager.getBestProvider says
If no provider meets the criteria, the criteria are loosened ... Note that the requirement on monetary cost is not removed in this process.
However, despite setting setCostAllowed to false the app still incurs a potential monetary cost.
What else can I do to prevent the app from using mobile data?