Determining programatically whether satellite GPS functionality is needed - android

Is it possible to determine programatically whether any background applications/services are using the sattelite GPS functionality?
I realise from searching SO that it isn't possible to disable it in code, but that I have to use a button shortcut which does:
Intent myIntent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(myIntent);
and click the relevant settings button.
I've written a maps application but have no access to a real phone at present and notice that the little satellite icon in the emulator's status bar doesn't reflect the state of the system setting. I'd like to try and conserve battery charge and am wondering whether the GPS stays on, draining the battery, if nothing requires its functionality.
I realise that disabling satellite GPS at system level may impact other apps, hence my question.

You are confused about things.
There are disabled/enabled and radio ON/OFF states.
As you say only the user can disable/enable use of GPS functionality via the setting you invoke. At this time the chip is not activated, only enabled. Battery is not drained.
When an application starts using the GPS, the radio will go ON so the chip will be activated, battery drained.
So once your application no longer uses the GPS, just stop using it, make it radio off (unsubscribe any receivers etc..) leave it enabled, and the user might disable if he really wants.

Related

Is it OK to retrieve cellular location when location setting is OFF?

On Android, we can retrieve CellLocation using this API
This API requires location(Coarse or Fine) permission to be granted.
We observed that API returns valid CellLocation even if global location-setting is OFF. Ideally, it should not give cell-location when location-setting is OFF.
Is the current API behavior intentional? Is it a bug in Android? Is it OK to access CellularLocation even if location setting is OFF?
There are two separate systems here:
App permissions
User toggles
If an app received the Location permission, it's allowed to use the API to get location whenever and however is wants (you should obviously take battery and data usage in consideration, but that's up to you).
If a certain settings toggle is switched on or off by the user, it's up to the API to turn off certain features from apps, it's not the app's responsibility to check system settings whenever it wants to use an API.
In your case the location setting can be toggled by the user to prevent usage of the GPS component to prevent accurate location tracking and to save battery.
This does not apply to cell-tower location as it's definitely not accurate and the data already exists on the phone so no battery power is needed either.
Android may in the future turn off cell-tower location when this setting is off, but until then you're allowed to use whatever the API gives you.

Prompting User to Enable GPS

Correct me if I am wrong:
1) You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
This leaves only two options:
1) Use new Google Play Services to prompt user to change these settings.
One issue with this is what if you just want to allow user to turn on GPS,
but not WIFI? The resolver will give them options to turn on both. How
can you just turn on one but not the other?
2) Send user to the settings application by firing off an Intent.
Now with 1) User must have current google play services installed.
If not they can be prompted to install it via standard GPS dialog.
Ok, now for 2) Sending user to settings application. I have the following problem:
When I fire off this intent, they not only get to change the Location/GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this? Anyway to bring up the Location/GPS Settings without the inner back button? Thanks.
You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
Correct, for obvious privacy reasons.
When I fire off this intent, they not only get to change the GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this?
No.

How often does the GPS check for location changes

How often does the GPS check for location changes without being specifically asked with requestLocationUpdates? Does that change when the screen is off?
My app just sets up a proximity alert, without any background service running, and it plays a sound when entering the proximity. I'm trying to find out the limitations to this approach, if there are any.
As long as the GPS chip is enabled it sends 1 location per second to the API.

Android GPS battery usage

I am writing a program in Android that uses GPS. It will prompt the user to turn on location services if it is not on (which I guess is equivalent to turning on gps ?). My question is: does the gps immediately start consuming extra battery power as soon as location services is turned on or it uses batter power whenever the location services is queried/used for a new location ?
The GPS starts working only when the location manager requests an update from it. Turning on the GPS in the device only allows programs to request locations if they want, but it doesn't mean the GPS is kicking in.
You can test it yourself: The GPS icon in the notification bar tells the GPS status. You can turn on the GPS, but the icon won't appear. Why? No application requests updates now. As soon as an application requests an update, the icon starts blinking (The GPS is initializing itself) and when it stops, it means the GPS is initialized and is currently receiveng updates.
The GPS consumes battery only when this icon appears.
My company wrote a blog post on this subject a while back. Check to see if its useful.
http://www.littleeye.co/blog/2013/03/29/understanding-gps-resource-usage/
But we missed talking about what happens when no app is actually requesting for a location update. And yes, as mentioned unless apps actually ask for a location update, they will not cause power drain. But note that even a single request for a location update (depending on coarse or fine grained request) can have unintended effects, as the device has to go thro various states before it can get back to its steady state.
Turning on location services is just permission given by user to applications for using location services. As long as any application not asks for location, power consumption is the same as with location sesrvices turnded on.
On the other hand - there is many applications trying to get location. Facebook, Camera, Android, many of ads libs, so yes - user can get battery life issues when GPS is unlocked.

Retrieving GPS coordinates when location services are not enabled

Assuming the device's "Use Wireless networks" and "Use GPS satellites" settings under Location is not enabled, is it possible to still retrieve the location coordinates.
Currently, the best is to redirect the user to the settings page is not enabled. I find this disruptive as needs to navigate away from the app.
If i am not mistaken, you can enable the settings programmatically (Am I correct?).
I don't need the exact coordinates, is it possible to get the cell tower ID without the settings enabled?
No. If the user doesn't want to give you his location, There is no way you can get his location.
This is a security measure and it exists for good reasons. If you try to subvert this, your app will be considered malicious.
Redirecting the user to the settings page is the best option.
Agreed - in earlier versions of android, you could programatically turn on the GPS - but more recent versions do not allow this to happen.
As Anup states - the common acceptable practice now is to redirect the user to the options page and allow the user to select the type and nature of GPS that the application is allowed to use.
Dont forget , you dont need to "leave the app" to get the user to turn on GPS, you can send them to the settings yourself:
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
This will then come back to your app where it left off - giveing the use a seamless experience, and one which they will be familiar with from other android apps.
Setting anything programatically without asking the user first is bad practice.
What you could do is, in case you can't get a location, ask the user to turn GPS on or tell him your app won't be able to work and will close.
switching on Location settings programmatically without the users consent is impossible let alone bad practice. You can prompt the user and direct him to switch on location settings or if you program tracks the progress of the device user, you can have the program send an alert of some sort telling them that the Location setting is off.
Deep dive into location has a set of best practices for Android's LocationManager. You do not need the GPS to be activated -- in many cases, the mobile network itself gives a pretty good approximation of the location without taking up extra battery.

Categories

Resources