BroadcastReceiver stop working on Xiaomi after couple of hours - android

I'm using Awareness API for my project and receiving actions via BroadcastReceiver. This is the question with my code: link. The problem is that everything works fine in all android version except in Xiaomi devices. Where BroadcastReceiver not receiving anything after couple of hours. I have tried many solution for this (such as this and this and turning battery saving off for my app), but nothing seems to work.

Google Awareness:
And whilst doing so, the API collates data from multiple sources to
ensure that the data provided is both accurate and of a high quality.
It also takes into account both the power and memory consumption when
accessing these signals - helping to ensure that the battery life and
memory usage of our applications do not have a detrimental effect on
the users device.
As this paragraph says:
It also takes into account both the power and memory consumption when
accessing these signals
and you say:
The problem is that everything works fine in all android version
except in Xiaomi devices. Where BroadcastReciver not receiving
anything after couple of hours
after couple of hours device may going to save more energy
You are listening for "Fence API" to register for changes in the users current environment it may consumes power and thus you do not receive broadcasts you may need to change the device settings to allow using of sensors such as location GPS and other relevant sensors

I think your problem is about battery optimization.
Android Marshmallow introduced Doze mode as a way of reducing battery consumption while the device is asleep. In your specific circumstance, though, you should disable it for your app.

Related

Android --design a background service for fast data acquisition

I am developing an android app for our custom healthcare hardware device that, among other things, should receive data from 5 sensos. The sensor data are sent via Bluetooth and is received using delegates that fire at 64Hz, 1000Hz, 4Hz,4Hz, and 32Hz respectively. I have successfully created an app that received the sensor data. Unfortunately, at the moment, the sensor acquisition runs on the main UI thread. This is unacceptable because it is expected that the app should keep recording the data uninterrupted throughout the day. After spending some time exploring my options, many tutorial online suggest to use a service to achieve this. However, there are many types of services (IntentServices, foreground services, background services...) to choice from and I am not sure what is the best approach. Also, my app will target android O and it seems that using background services are somehow discouraged. Would any experienced android developer gives some suggestion on how to tackle this problem? Please note that, at the moment, this is just a demo and the battery and other resource usage is not an issue.
Best approach for things that you want to achieve is to use Foreground Service, that will keep connection with ble device and get notifications from gatt services. Also you will need to use WakeLock to keep your service alive in sleep mode.
One year ago was making sample app for internal ble device. Check bluetooth/gatt package, was really useful such implementation.(project isn't good for production, but as sample/demo is pretty nice)

How ActivityRecognition works?

I am eager to know how ActivityRecognition which is in GooglePlay Services works?
I think activities are recognized by accelerometer data.Is it right?.Please give me the details how it goes?
I was looking for this answer also and your post was one of the top results on Google. I did a little more digging and found this https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html which says:
The activities are detected by periodically waking up the device and reading short bursts of sensor data. It only makes use of low power sensors in order to keep the power usage to a minimum. For example, it can detect if the user is currently on foot, in a car, on a bicycle or still.
It doesn't explicitly say which sensors it uses, but we can safely assume that accelerometer is one of them. Since it says sensors (plural) it evidently uses others. But since it says low power you don't have to worry about it using GPS or anything like that. However, it does say that it wakes the device up which would bring it out of its super power saving mode. So, even though it is low power you still may not want it running every 5 seconds all day long. The documentation further down says:
A common use case is that an application wants to monitor activities in the background and perform an action when a specific activity is detected. To do this without needing a service that is always on in the background consuming resources, detected activities are delivered via an intent. The application specifies a PendingIntent callback (typically an IntentService) which will be called when activities are detected. See the documentation of PendingIntent for more details.

How can i save Battery power using in writing app

In Android 4.4 kit-kat version I saw my writing app is using high battery power ...
in my application I am using Network service to fetch data from server.
so I search the solution to save the battery power .. I found this topic
http://developer.android.com/training/efficient-downloads/efficient-network-access.html#PrefetchData
Any others ways to save the Battery Power Useage and best pratice for reduce battery power using in application.
By taking steps such as disabling background service updates when you lose connectivity, or reducing the rate of such updates when the battery level is low, you can ensure that the impact of your app on battery life is minimized, without compromising the user experience.For more take a look here. Check which part of your app is consuming the thread profiling with trace View. And you also need to aware of your app performance.

Android GPS and battery usage

I have 2 android applications A and B, and both of them are reading gps values based on different parameters. Considering both the apps are running on the device, which of the folllowing approaches would be better?
Both A and B are to be different apps, each one with a component to read from GPS.
To develop a third application with a remote service component to transmit GPS data to both A and B
Would battery usage be minimized by going for the second approach or will the GPS component read once and serve all processes, as in the OS?
Please help
There is a very good explanation given in the Android Developers Website about Location Strategies. I would suggest you to take a look at the code examples on the page.
In both of your approaches i believe second approach is quite better because Turning on/off GPS is a quite expensive operation in terms of battery usage.
GPS’s battery draining behavior is most noticeable during the initial acquisition of the satellite’s navigation message. Acquiring each satellite takes 12 to 30 seconds, but if the full almanac is needed, this can take up to 12 minutes. During all of this, your phone is unable to enter a deep sleep. A-GPS (Assisted GPS) partially solves this, by sending the navigational message to your mobile device over your cellular data network or even Wi-Fi. As the bandwidth of either of these greatly dwarves the 50bps of the GPS satellites, the time spent powering the GPS antenna or avoiding deep sleep is greatly reduced.
Referred from this.
I think the most battery-efficient way would be to poll the GPS location with app A normally, and in app B, use LocationRequests and use setPriority() with PRIORITY_NO_POWER. As mentioned in the docs, PRIORITY_NO_POWER will make app B get updates only when another app gets GPS updates (in this case, app A!!). I haven't tried it, but it should work. It definitely saves you the hassle of an extra app :)
Some more info on Google Play Location Services here and here.
is it the same as OS gPS component will run once to serve all
One GPS serves all.
There is no half GPS saving half the power.
But there are other location providers like cell tower and Wifi locationing which uses less power.
But if you need GPS it is absolutley no difference how many apps uses the GPS service.
If GPS is enabled it uses full power.
For the sake of compatibility and function I would suggest having a third process or program which reads and outputs GPS data, as multiple processes polling data from GPS is less efficient.
It would also be faster to have those two apps read the output of a single GPS tracking app and not needing individual components in each app to do so.
For the sake of power the GPS will use the same level of power regardless, though if it's polled more often due to two applications using it then it may use more - though the amount is likely to be minimal unless there are constant requests for location.
Though this may not be the question it would be most power efficient to have the third application poll GPS at specific intervals and the applications may read from its output rather than search location every time.
Second approach seems to be more appropriate but not sure about battery drainage.It depends upon how you implement it.
Also I would suggest try to use passive providers.Refer following link help it works :)
http://fypandroid.wordpress.com/2011/04/11/298/

Android battery usage

My goal is to decide whether my application has a battery issue or not so I want to add a module that checking the percentage of my app battery usage each interval time.
How can I retrieve the values of the battery usage for each application (or at least my application) by percentage?
I saw several answers in stack overflow saying that there is no way...
Can I do something? even reflection is good for me.
Besides, is there any good dev tool that could help me investigate my app battery consumption? (by components, i.e. wifi, gps, gsm etc.)
thanks
The author of BatteryIndicator wrote in his FAQ-How_does_Battery_Indicator_work?
How does Battery Indicator work? / How does it know what percentage
the battery is at?
The Android system has a mechanism where you can register your app to
be notified when the battery status changes. So Battery Indicator has
a background service that is technically always running but is
essentially always sleeping and using basically no system resources
(because it doesn't do any polling -- it just sleeps and waits to be
notified by the OS when something changes), then when the battery
charge (or plugged-in status) changes, the system wakes it up and
tells it what the new battery charge (and status) is. Then it takes
just a few milliseconds to change its icon to reflect the current
charge (and status) and goes back to sleep.
If you're technically oriented, the documentation for the core API
that Battery Indicator uses is here:
http://developer.android.com/reference/android/os/BatteryManager.html
and the actual source code to the development version of the app is
here: http://code.google.com/p/battery-indicator/source/browse/trunk .
The app shows consumption of different modules
Phone in Standby 59%
Akku in Standby 39%
Display 4%
But i donot know how this is implemented.
How can I retrieve the values of the battery usage for each application (or at least my application) by percentage?
There is nothing in the Android SDK for this, sorry.
Besides, is there any good dev tool that could help me investigate my app battery consumption? (by components, i.e. wifi, gps, gsm etc.)
Buy a Qualcomm MDP and use Trepn. Unfortunately, this is expensive.
Download "Dr. Power" from Android Market.
This app has been developed by a company that has the exact problem.

Categories

Resources