Save battery power consumed by gps services in android - android

I am developing an application which has two GPS services. One of which is location tracking which send location updates at every 2 min to server and another service is cyberseatbelt which checks for speed of device when location updates.
With these two services, battery consumption is 77% displayed in my mobile. Without these two services, no battery consumption is displaying.
Is there any solution to save battery power on device while keeping the desired functionality?

You have to tell what you have done to make the battery consumption so high. (Not even clear if battery becomes 77% after 1 minute or 15 minutes or 1 hr).
How are you accessing GPS? Are you running a handler/thread to periodically poll the GPS. If yes, this is wrong approach. You can ask Android to inform you on location changes.
GPS services are usually memory hungry. Do you need GPS services or just looking for location updates? Android comes with a good startup doco for location based services . http://developer.android.com/guide/topics/location/obtaining-user-location.html
Try following the steps in this doco to find best user location.
Make sure to stop listening for updates at the appropriate time. Users will not be happy that one app tries to drain the battery even when it is not running.
Try making the app as a background task.. i.e a Service or BroadcastReceiver

Related

How to track (if possible) an Android device (latest versions) in the background at regular intervals?

Premise
The user should always be informed of the use of his sensitive data (like collecting the location in the background), this question aims to better understand the latest limitations introduced on Android use of location and background operations.
Problem
Is it still possible (on Android latest versions) to create a location tracking service that would keep tracking the device location no matter the application state (foreground / background) nor the device state (doze or standby mode, app buckets) in order to be able to collect location in a consistent way ?
Assuming that the GPS and internet connection are enabled and available, is it possible to collect the location, let's say every 10 minutes, or the device going to doze mode or standby will anyway restrict the app possibilities after some time and defer the operations (like network operations), making it impossible to keep getting regular location updates ?
On latest android versions, starting from Android 8.0 (API 26), new ways to improve battery performance and secure the users privacy have been introduced:
Background limitations
Background location limits
App standby buckets
What I tried
From my understanding, a foreground service looks like the best option:
keep informing the user (notification)
the system does not kill the service after a few seconds (as for background services starting from API 26)
less likely to get stopped by the system (START_STICKY flag to restart otherwise)
can acquire a wake lock
Still it seems that the app needs to be whitelisted to avoid battery optimisations and even battery optimisation need to be disabled in order for the service not to be stopped/deferred.
Expected result
Receive location updates at regular intervals, every 10 minutes for instance
You have to use FusedLocationProviderClient in a service to give you location in specified time intervals or distances. If you choose distances you have to watch location accuracy as well. See this article.

Battery drain issues with Android GPS recording service

My service records the location of the user and sends it to Firebase every X minutes. I have tried changing X from 1 minute to 5 minutes, however the change in battery drain was less than 1 percent. In both cases it works out at about 5% used by the app every 3 hours.
I am trying to understand how increasing the GPS interval by 500% had little or no impact on the battery life. Not only is the GPS firing 1/5 of the time, but there is also 1/5 of the data being sent/received to Firebase.
When the watching location is turned off, battery drain is 0.
Any ideas as to what is causing the drain? Also, what kind of battery drain should I be looking at for getting a GPS location every 5 mins and sending about 50 bytes of data with it?
An immediate concern is how you connect to Firebase. Keep in mind that Firebase will keep an open connection to the server from the moment you call new Firebase(...). If you only want to periodically send/listen for data, you'll needlessly be draining the battery.
You can programmatically manage the connection state with goOffline()/goOnline().
If you're only sending updates, you can use the Firebase REST API to write the updates. This won't keep an open connection, or at least leaves it up to Android to determine when to close the connection.
Turned out the major cause was the mobile data. As soon as I made it require wifi to use firebase the battery drain dropped from 20% a day to 2%.

Will it be a good method to turn on and off GPS when not using, in order to save power?

I'm developing an Android application. I needs to read the user's current GPS location periodically (assume in every 1min). In order to save the battery power, I thought of turning off the GPS connection when my app is not reading the GPS values and turn on when it wants to read the location (So in every 1min GPS will be turned on and off).
So my questions are;
Is this a good method to save the battery power?
Is there any standard method like putting GPS on sleep mode when it is not using?
Also will it actually save power by turning on and off the GPS connection?
GPS only needs power when it is actually used, so in theory, turning it off would not save any power.
But, in practice, a lot of apps and services use GPS every now and then, so turning it off would prevent those apps and services to turn GPS on and would therefore save power.
Is this a good method to save the battery power?
No, because one minute is too frequent of a polling period. GPS takes a while to "warm up" (e.g., receive signals from satellites).
Is there any standard method like putting GPS on sleep mode when it is not using?
Request a less-frequent polling period. Or, if your app will only be distributed via the Play Store, consider using LocationClient from the Play Services SDK, as it manages that sort of power tuning yourself.
Also will it actually save power by turning on and off the GPS connection?
You don't turn "on and off" the GPS connection. You merely indicate if your app needs GPS location data. Whether the GPS radio actually powers down is up to the OS, and that will depend in part on what other applications are running and what they request.
In general, you want to want to unregister from location updates when you no longer need them, and specify a long polling period (e.g., in requestLocationUpdates()) to help the OS manage power in between polls.

Android App power consumption using GPS

In my app I am going to use the GPS for getting direction when I am trying to use GPS system. on that time my mobile % of charger will reduce immediately, if there is any idea for overcome from in this issue.
You have to tell what you have done to make the battery consumption so high. (Not even clear if battery becomes 77% after 1 minute or 15 minutes or 1 hr).
How are you accessing GPS? Are you running a handler/thread to periodically poll the GPS. If yes, this is wrong approach. You can ask Android to inform you on location changes.
GPS services are usually memory hungry. Do you need GPS services or just looking for location updates? Android comes with a good startup doco for location based services . http://developer.android.com/guide/topics/location/obtaining-user-location.html Try following the steps in this doco to find best user location.
Make sure to stop listening for updates at the appropriate time. Users will not be happy that one app tries to drain the battery even when it is not running.
Try making the app as a background task.. i.e a Service or BroadcastReceiver

Which is the best way to get continues location updates from running background service with battery optimization?

I have to create an app which runs a service in background and continually update the current location on the server or we can say i have to send my current location at some points. The solutions i have think are following. please look at that and give me some idea.
Running an service in background with boot-starter.
Implementation of alarm manager so service can be started automatically if android kills it.
If my current location is in the radius of the 500 from my points than start to update on server.
and other logic which i have think to prevent continues server update.
I have research on it and found it consumes much battery of phone. So please suggest me how can i optimized it.
There are some ways that can keep your Battery work for a long time though you are using GPS Application.
Turn the GPS function off when not in use, then on when you need a
location.
There are some more ways that you can keep track that GPS doesn't drain much Battery, just read this BLog to get some more idea about it.

Categories

Resources