make display to remain turn on - android

I want to have my control to make display remain turn on on some event and release my control on display turn on/off based on some other event. I know that I can easily do this using wakelock. But device battery life will be significantly affected by the use of this API. Is there any other way to do so?

It is good that you are considering battery consumption in your app, however, what you are effectively asking is if there's any way to make the display use less power, since regardless of the method used to keep it on, you are keeping the display on.
Since the display is usually the largest battery drain on modern smartphones, I'm afraid the answer is no, there is no way to keep the display enabled and at the same time significantly reduce power consumption.
You may be able to dim the display, but that is unlikely to result in a significant power saving and WakeLocks are the correct way to use this functionality.

Battery life will be significantly affected by your app keeping the scree on all the time, so you must think twice if you want your app to use this functionality. If you indeed need this option, you can use getCurrentFocus().setKeepScreenOn(true); Hope this helps.

Related

How to measure battery usage of my application?

Well i have read a lot of answers of similar questions (even if they are old from like 2013-2014) and i understood that it is not possible to know it exactly since android doesnt count the hardware usage as usage of the app, and some other possible problems like services etc.
At the moment I'm trying to test the perfomance of an App using a protocol to reach a goal and the perfomance of the same App using another protocol (not well known by everyone) to reach the same goal, the default android battery analyzer is good for me since both cases are like 90% the same and i know how the protocols work
My problem is that i'm not sure which one is the best to measure the mAph consumed by my App, i know that there are some external apps that shows it but i would prefer using the one of default, I believe this is something important not only for me but for other people who might have to compare different protocols.
I know that i can measure it programmatically and I've done it too, i save the percentage when the app is opened and how much has been consumed until it gets closed, but it isnt an exact measure since while the app is opened some other apps can do heavy work and add some kind of noise of what i'm measuring so i would prefer to use the android's battery analyzer.
Get a spare device. Load it completely, then run the protocol until shutdown without other interaction (no youtube or anything), note the time it lasted. Repeat with the other protocol. Imho that is a fair way to compare. Note that every device behaves differently and it may or may not be possible to transfer this result to other devices e.g. with different network chips, processors or even firmware versions.
For a more fair comparison I think you should compare how the protocols work. I.e. number of interactions, payload size etc. because the power consumption can only ever be an estimate.

need an idea to save power consumed by app that do continuous recording

I have an application that depends on recording all sounds and analyses it and notify me when it records a specific tone.
So this app consuming battery power as it works all time to detect the sound tone wanted.
I need an idea to prevent this problem please.
Thanks in advance.
It appears that you are not allowing the processor to drop into a quiescent low power state. To allow the processor to conserve power, you need to have the processor idle as much as possible. If you are continuously sampling, this isn't going to happen. My answer here can give you some background.
I suggest you do the following:
Find out what is the minimum fidelity you can use and still identify the tones you want. To say this differently, determine the maximum sampling interval. For example, you may find that you can get by with sampling every quarter second and still identify the tone you want. This will allow the processor to drop into an energy conservation state.
Make sure you are using interrupts and not polling, i.e. use something like usleep(). So to check every .25 sec, you'll use something like while( running ){ sampleTone(); usleep(250000); }.
Check your sound sampling device's capabilities. It may have the ability to do something more sophisticated that will further minimize the number of samples/sec you need. For example, it may allow you to send the samples directly to disk or memory without requiring the CPU to wake up.

Android Battery level in mA

I need to get statistics about the battery in milliAmpere.
I've already found how to get the battery percentage and voltage but not the current.
There are applications like this that can do it but i wonder how.
Thank you
I believe the only way to get the current is via the logcat. The system will occasionally post it to there so you'll need to go back find the last update for it.
There is no way of measuring current drawn from within the system - this or any other app can only estimate it based on timing information and voltage discharge that the system reports. You are not likely to have anything accurate based on just that though - to have more accurate information you need an accurate device power model.
There is a nice article by the Android framework guys about how the power model is built (also applies to the built-in battery power monitor).
TL;DR
Measurement can be accomplished using a bench power supply or using specialized battery-monitoring tools (such as Monsoon Solution Inc.’s Power Monitor and Power Tool software).
Need to control what components of the device are active (screen on/off/brightness level, cellular/wifi/bluetooth radio, gps, CPU, etc.)
Based on those you build an energy profile similar to the example at the bottom of the page
There are also typical values in the table in the document. Warning: these are highly hardware-dependent
You can then apply the model by monitoring the state of the device and activities of applications (screen state, foreground/background, CPU/network use by an app, etc.)
This is a lot of hard work (sorry about that :) ), but there isn't another good way - it is actually an active research problem...

In app battery usage

Is there any way to determine what is using power in an app? From what I have found, the most granular I can get is how much power an app itself is using. I want to know what I can do to make my app more efficient in the most empirical way possible as it is easy to justify a change when there are numbers to back it up.
Is there any way to determine what is using power in an app?
You can buy a Qualcomm MDP device and use Trepn to get fairly accurate and detailed power analysis of your app. However, an MDP is expensive.
Otherwise, there is little you can do, simply because current Android production hardware is not instrumented to try to collect this level of information. Even the Battery screen in Settings is mostly just an educated guess.

Check the performance of the application?

Hey, I finished my code and everything works as it should but I'm wondering since smartphones have limited battery, CPU .. How can I check if my application will run good on older phones? and how can I check if my app consumes the phones battery?
Thanks
The only way to really know it to test the app in the phones.
That said, you can profile it and make educated guesses based on how CPU-intensive is your app, for how long is it running, if you have services using cpu continuously, etc.
There are a few things to consider:
The main battery drain is the screen. If you keep any kind of screen lock (even dim), it will destroy the battery.
Any other lock (wifi, etc.), will induce battery drain. Do you use them? Do you need them? Do you release them as soon as they're not needed?
Do you have hardware listeners (e.g., location, accelerometer), unregister them as soon as they're not needed
Take a look at this video: http://www.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html
Also take a look on
http://developer.android.com/guide/developing/debugging/debugging-tracing.html

Categories

Resources