Location is set by GPS although GPS is supposed to be disabled - android

I am using the following code for getting the location:
localCriteria = new Criteria();
localCriteria.setAccuracy(Criteria.ACCURACY_FINE);
localCriteria.setAltitudeRequired(false);
localCriteria.setBearingRequired(false);
localCriteria.setCostAllowed(true);
localCriteria.setSpeedRequired(true);
localCriteria.setPowerRequirement(Criteria.POWER_LOW);
mProvider = mLocMan.getBestProvider(localCriteria, true);
mLocMan.requestLocationUpdates(mProvider, 0, 0f, this);
Although my phone settings is set to Medium Accuracy ( meaning network and wifi, no gps), but when I run the application, it displays the GPS icon on the on the notification bar with the location being set by GPS!!
Shouldn't the GPS be disabled and no location acquired as a result? I am not sure what is happening
Thank you

The icon is not only used for GPS-locating but for all location-acquiring. Setting the location settings to 'medium'/ power saving means that GPS isn't used to acquire the location, but wifi and mobile network cells are. The phone can still locate itself, thus the icon appears.
I don't even know though how to completely disable any location services on Android 5.0.
You can check for yourself what Provider (source of locattion) was used when receiving the Location. If the Provider IS Gps, this might be an actual bug in your firmware / Android version.

Related

Android location mode, no GPS, options in AOSP

I'm working on an Android M STB without a GPS chip. In Android settings, Location, I get three choices for Location support -- High Accuracy, Low Bat, GPS Only. The system is defaulting to High Accuracy mode.
The problem here is that when wifi.getScanResults() is called from a background service and one of the location modes needing GPS is enabled, I don't get any results back. The call works fine from a foreground app, only background services are impacted by this. When I change the system over to Location mode Low Bat (which does not require GPS) the background getScanResults() call works as expected.
How do I modify my AOSP build so that the High Accuracy and GPS Only choices won't be presented to the user since there is no GPS chip?
Have you tried modifying the LocationManagerService class so it doesn't load a GPS provider? The following might be what you are looking for.
https://github.com/android/platform_frameworks_base/blob/nougat-release/services/core/java/com/android/server/LocationManagerService.java#L453
The default location mode is set by def_location_providers_allowed in frameworks/base/packages/SettingsProvider/res/values/defaults.xml. Its value can be either gps (GPS only), network (Battery saving) or gps,network (High accuracy).
You could therefore set def_location_providers_allowed to network (e.g. in a device/vendor overlay) and disable or hide the Mode option to the user in Settings → Location since you have only one choice (see packages/apps/Settings/res/xml/location_mode.xml).

Android gps provider and gps icon

Today when i was trying my code, a few doubtful thing appeared in my mind about gps provider, gps hardware, gps icon and fine location permission.
I observed my code and gps icon on Samsung galaxy s3, Htc one m8. And gps is disabled
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 10, 0, this, Looper.myLooper());
...
#Override
public void onLocationChanged(Location location) {
mListenerRef.get().onLocationChanged(location);
}
Galaxy s3 - Gps icon didn't appear, it didn't fire onLocationChanged method. (Thats okay)
Htc one m8 - Gps icon appeared, blinking, and fired onLocationChanged (But how ?)
At this moment questions pops up
Does ACCESS_FINE_LOCATION permission give the app override gps status on some devices?
So, could the app receive location even gps disabled ?
And then i enabled gps on galaxy s3
(First 2 minutes) Gps icon appeared(but not blinking), fired onLocationChanged method (But how ?)
(After 2 minutes) Gps icon appeared(blinking), fired onLocationChanged method
Again questions pops up
What does gps icon blinking mean ? any extracanonical meaning ?
Does the blinking mean gps hardware trying first fix ?
Or blinking means the provider firing onLocationChanged method ?
What does gps icon blinking mean?
-> Well I hope u r aware that GPS provider dosen't work under roof. So it is completely impossible to get Location update from GPS provider under roof. In such situation if user enables the GPS then the GPS blinking icon appears notifying to user that it is searching for GPS.
-> Once it finds the GPS the icon dosen't blink anymore and u'll get location updates from GPS provider.
-> A still GPS icon means Android system is ready to send location updates from GPS provider.
Htc one m8 - Gps icon appeared, blinking, and fired onLocationChanged (But how ?)
-> It sounds weird getting location updates without enabling it. I'm not sure how u confirmd that u got the Location update.
-> I'll recommend u to check if GPS provider is enabled and then request for location update.
Fine_location permission will enable user to have update from gps, wifi, network. So if gps is unavailable still onlocationChange() can be fired because a recent location may have been fetched via wifi/network.
(quote from the link: http://developer.android.com/guide/topics/location/strategies.html
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.
)
How your phone showed gps icon without gps being enabled, I doubt it is possible.
With HTC One (M7) the APP has permission to use the GPS and that makes 'GPS' fair game - ('GPS' = 'GPS Spoofer', AGPS [if permitted], an APP that uses WiFi and GPS [thus position is almost always immediately available], and, of course, the Phone's real Hardware GPS / GLONASS / Galileo / etc.).
The HTC UI has an Icon for the Application that uses the GPS (whatever the Phone thinks the Provider IS, a few APPs do check Provider; they don't accept spoofed Locations, EG: Most Subscription APPs, Google Play Store, abrev. GPS;) ).
A second Icon appears for the Hardware GPS. It flashes while it waits for enough Satellites. Indoors, without WiFi, with AGPS, I can get a lock in less than 1/2 min.
You probably want to check the Error when you get your LC Message, since if you're over 100 M off you don't really know where you are and probably don't have a valid position; pending calculations from one more (weak) Satellite may be enough to get you below 50 M Error, at which point you should start accepting the Location as valid (your APP might want to record Error with Coordinates, then Locations can be displayed with a circle representing the uncertainty).
When Developing you want to be certain to buy the most popular Phone (so you have real Hardware to test on, and support the greatest number of Customers), and to buy a FEW Phones with the Hardware that you want your Android APPs to control - in your case buy Phones with different GPS Hardware, for others they may need to buy a few Phones with different Camera Hardware (or WiFi Chip, etc.).
Between the Cell Phone Mfgs version of Android, their UI, and the manner in which their GPS Hardware operates (along with other APPs you have installed, like a Spoofer) you have a LOT of variables that your Program must juggle and many situations (Error Returns) that it must allow for to operate identically on as many Devices as possible.

get coordinates without gps (android)

I'm developing a android app and I want to receive coordinates from a smartphone. Two questions:
1: GPS is enabled, but there is no signal, so I have no coordinates. How can I check, if GPS is sending coordinates or not?
2: If GPS is enabled and there is no signal, which other method can I use to get the coordinates from the smartphone?
Getting coordinates requires using the location services, which by default uses all manner to determine location, not just the GPS, but cellular signals as well. Here is a tutorial on using the location services in Android.
One word of advice - if you are going to use GPS and generally distribute your app, know that the GPS service is VERY battery intensive. It requires judicious coding to not drain your users battery. You have been warned!
1) fetch device coordinates using locationService.
mContext = getActivity();
mLocationManager = (LocationManager) mContext.getSystemService(Application.LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(mProvider, 60000, 100, mAttLocationListener);
boolean gpsEnabled = mLocationManager.isProviderEnabled(mProvider);
2) You can still get rough estimates using location information stashed in wi-fi

How to force android's locationlistener to fetch provider location?

I have written a small app that receives the location from mobile 3g/wifi by using locationManager & NETWORK_PROVIDER parameter.
according to google's api it will get the location i wish (the other option is using the GPS_PROVIDER)
what i really desired was the WIFI location. I wanted to see its behavior and how the phone gets its location (i.e with wireshark)
in order to do that, i changed into flight mode & activated wifi.
then, i launched the app and clicked the button which starts the NETWORK_PROVIDER location service by calling the requestLocationUpdates function with time parameter = 10.
what that actually happened is that i managed to get the location but saw no traffic at all in wireshark.
could it be that Google gives me the approx. location in advance, when connecting to the wifi? (its the only explenation)
If so, is it possible to clear that cache, or whatever data it have stored, and force the phone to get a new (but the same) location?
Thanks in advance,
Eran.
Have you tried re-booting the phone, just so to remove any cache files which might be storing the location?
Since NETWORK_PROVIDER use cell location, wifi ssid and their signal strength to get your GPS coordinates.
Since you are in flight mode and cannot get cell location, just try to switch the connected wifi , maybe google service will be invoked to get new location.

Android Location Wifi doesnt work after rebooting

I am using this code to get the location provider and location.
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
mBestProvider = mLocationManager.getBestProvider(criteria, false);
mLocation = mLocationManager.getLastKnownLocation(mBestProvider);
If I turn off the GPS, the location is by network, but if I reboot the phone(so I loss the last position known) and with the 3G data connections off. So I am only using WIFI, I cant get any provider thus therefore any location. However google places app can locate me. I think it might be getting the lastknownlocation.But in that case my others applications should be able to get that location. Any idea whats happening?
The way you are calling this it will return all providers enabled or not because you are passing it false which is probably your intention but have you checked the return string?
mBestProvider = mLocationManager.getBestProvider(criteria, false);
You might be getting the gps provider, or you might be getting the network provider, I have learned not to trust the criteria mechanism because it seems to work differently per carrier and device (I have had some weird bugs reported because of this)
So I always ask specifically for gps and network providers and check last known for both, then use an algo to determine the best one to use.
The network provider can use cell or wifi hotspot/routers to determine location (google keeps a database of wifi information) so it's possible to get a fix with just wifi, not saying that is whats happening but it could be.
If that bears no fruit then it's possible that they are simply caching the last location update in preferences, some applications do that. To test the thesis, failing all of the above just leave the phone in that state and move to a very different location with the same properties if possible, should only take 2000 meters or so. If your app still reports null and places reports the old location you have your answer.
If places did report the newer location with wifi, and your app cannot (assuming you actually verify you are getting the network provider) then there is a chance they are using a private API via the Google Location Server (GLS) / MASF server via partial cell / wifi info but that's at the extreme end of the tin foil curve.

Categories

Resources