Android: FusedLocationProviderApi: LocationRequest vs Device location mode - android

I'm using new Location API (FusedLocationProviderApi) and get confuse about it.
I intend to use LocationRequest.PRIORITY_HIGH_ACCURACY. But, on device, if user choose the location mode is save battery (network only). -> What is the bahevior for my app?
Does it update with hight accuracy (with internet, gps..) OR
Does it will be limited follow the setting of user?
Please correct me if i missunderstand anything.

Related

Cordova Ionic Android Location Sometimes Not Accurate

We use in Cordova with plugin "cordova-plugin-locationservices"
Sometimes we get location that a few km away from real location.
we call to "getCurrentPosition" with next options:
{
timeout: 60000,
enableHighAccuracy: true,
maximumAge: 0,
}
Someone use in this plugin and use in another options or recommend on another plugin.
At first we use "cordova-plugin-geolocation" with same options but it's also sometimes return not accurate position.
I've written extensively on this topic at https://breautek.com/articles/geolocation-accuracy.html
But to summarise there are a number of reasons why you aren't receiving the accuracy that you're after.
The two main contributors to inaccurate readings are 1) Settings & 2) The environment.
Natively, the GPS service operates in two modes: Fine location and coarse location. Fine location will allow you to get approximately up to 3-5 meter accuracy and is generally used if you require information such as the specific street. Coarse location gives you a very low accuracy reading that can only be useful to determine the location of the user's state or country.
Settings includes both programmatic settings, such as the enableHighAccuracy parameter, and they include User device settings, which is configurable by the user on based on their own location preferences.
The developer obviously has control over programmatic settings, and it looks like you're doing just that. However, the developer doesn't have access to change user preferences of the device. Just because the user has consented permission for your app to use location, doesn't mean they have location services actually enabled, or even configured to provide fine location. The specific settings can vary from device to device or by OS version to OS version. But generally speaking they usually have some sort of "Device/GPS only", and "High Accuracy" (sometimes labelled as "Bluetooth/Wifi/Mobile") setting for geolocation. It's the app's responsibility to handle these situations.
In my apps, I use the mixture of the cordova-plugin-geolocation as well as the third-party diagnostics plugin. With the diagnostics plugin, you can check if permission is granted, including for fine/precise location, as well if location services are indeed enabled.
Lastly, the second issue could be the environment. Even if the device is configured and the app has permission to use fine location, you still may not actually receive accurate readings. This can be caused purely based on the environment. Being located in a concrete office building for example hinders a lot of GPS capabilities.
It's recommended to pay attention to the accuracy field in your GPS callbacks, which will tell how confident the GPS service is that the given GPS point is accurate. The accuracy reading is in meters which tells you that the true location is within X meters radius of the given location. So in otherwords, the lower the number the better.

FusedLocationApi.getLastLocation always null in background

I am getting location in background through Fused Location Provider but always getting null Location.
Can you please help me
Are you using an android emulator?
The fused location provider manages the underlying location technologies, such as GPS and Wi-Fi, and provides a simple API that you can use to specify the required quality of service. For example, you can request the most accurate data available, or the best accuracy possible with no additional power consumption.
well, it happened to me before when I used some android emulators with low API levels (Lollipop L25). so the emulator doesn't have any location info to return
but it will work on a physical device.
now if your problem just in the background what background service are you using
can you share some code?

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 Mock Location "Teleporting"

I've been trying to get mock locations on my OnePlus One working for quite some time now, but I have unfortunately been unable to determine the cause of this. Essentially my issue is that when setting a mock location, they do work, but for some reason my location appears to "teleport" between where I set my mock location and my current location. I've been using Google Maps to test my current location. Following the guidance of this answer, I set my location mode to "Device only", but it appears to still be happening. Furthermore, I turned off WiFi completely, to no avail.
The app I am using to spoof my location is here. I've tried other apps to the same effect. My phone is running the latest CyanogenMod 13 snapshot (20160419).
If anyone would happen to know how to solve this, it would be much appreciated :)
The steps given below worked for my Nexus 6:
(I have assumed that your device is rooted. If not you need to root it first)
Install Xposed framework. You can use the tutorial here.
After Xposed is installed go to its Download section and install the module Mock Mock Locations. Then go to the Modules section in the Xposed app and activate the downloaded plugin(needs restart).
In developer options select the mock location app you are using in Debugging->Select mock location app
Download the app Disable Service. In the app select the System tab search for the service named Fused Location and disable it. Also search for the service group Google Play Services. Inside it there will be another
Fused Location service. You need to disable it too.
If it is still not working try disabling Google Location History as given here. Also set your GPS accuracy to Device Only.
Install Fake GPS Location app in your Android device and set your desired location inside the app. Your device will behave as if it is at the location you have set. Don't forget to select Select mock location app in Developer options in your device Settings.
In case someone has issues with mock location software to get working:
override fun onLocationResult(locationResult: LocationResult) {
var LastLocation: Location = currentLocation
if (LastLocation.longitude > X.XXX && LastLocation.longitude < X.XXX && LastLocation.latitude > X.XXX && LastLocation.latitude < X.XXX) {
LastLocation.latitude += Y.YYY; LastLocation.longitude += Y.YYY
}
X.XXX is a placeholder. Set a bounding box for your ow current location to shift your location to the new destination by changing Y.YYY
With something like this, you could shift your location and simulate hardcoded from your home/office location your desired location.

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.

Categories

Resources