How to reboot android device - android

How to shutdown and restart android device in my application.
please give me a suggestion if is possible or not.
I search a lot but no code work for me.

Based on what you said your intentions are, what you want to do is not possible in Android. If you are rooted, you can shut down your phone, but there's no way to wake it up at a future time.
What you might want to look into is to simply put the phone to sleep as much as possible -- place it in Airplane mode and turn off sound. ... and then re-enable all that at a given time.
If you don't want to code it all yourself, there are various scheduling apps out there, including Tasker (which can do much more).

Related

Android / PocketSphinx: listener goes in standby a while after screen goes off

I made a simple app that responds to vocal commands using PocketSphinx to understand commands and standard Google's library to speak, in a sort of conversation.
It's working well but I have a problem and I'm unable to undesrtand what's happen: after the screen goes off, but maybe it happens also after a while, without talking for a while, when the screen is on but opening another app, the application stops retrieving my vocal commands.
When I unblock the phone and/or return to the application, everything restart to work without problem.
I need that this application works in the same manner also when the phone is in standby, but I can't understand what could be the best solution (the best or simply the possible one):
does using wakelock could change something?
does transorming the activity in a service could be the solution?
I tried to disable battery optimization too, and also I tried with an exernal application to impose PARTIAL_WAKE_LOCK to mantain the CPU on, but nothing change.
Does someone has got some experience in this case and can explain me how to do?
Thanks a lot in advance!

Is it possible to completely disable the Doze mode and Standby mode?

I have a requirement to create an app that should run 24/7. I don't care about battery drain, becoz app will not be submitted to PlayStore and its only for the selected user.I also understand app will only last for one day, that is acceptable in my case.
The application functionality mainly dependent on network and Bluetooth functionality and the most of the code written in pre marshmallow and changing the whole implementation is not a right option for me now.
So is there any way to create the app without any restriction? Also, As observed some of the Device manufacturers put an extra layer of battery optimization to make this worse.
I tried to create a dummy foreground service with partial wakelock, but this not seems to be working. and even whitelisting the app didn't solve the issue.
There is no proper documentation from Google about what are the functionalities will be affected from doze/standby. According to Google doc the background task will not be suspended, it only deferred until the next maintenance window. If that is the case, App should be able to print all the app that is missed during doze period. But as observed app will print the log only during the maintenance window. The is will break the expected behavior.
Whitelisting is a good option but app will be still be affected by the doze mode. What is the reason to restrict the app behavior even when the user explicitly chose not to? It very frustrating when the app behaves differently in different device OS, Manufacturer etc.
Sorry for the story. I would like to understand is there any way to completely disable Doze and standby mode without changing the existing implementation? I have gone through the various document, but there is NO WAY to achieve this 100%. Please share your thoughts
I have a requirement to create an app that should run 24/7
Write a program for a desktop operating system. Or, perhaps find a mobile device that runs Linux and write a program for it. Or, create a custom version of Android that disables Doze/app standby. Or, see if there is some Android hardware that meets your requirements and does not apply Doze/app standby (e.g., devices that naturally are always plugged in, such as Android TV or a Chromebox).
So is there any way to create the app without any restriction?
No, sorry.
I would like to understand is there any way to completely disable Doze and standby mode without changing the existing implementation?
No, sorry.

How to set a timer programmatically to boot an Android device at a specific time?

I'm currently working on an app for this kind of device:
link. I want the user to be able to set a timer to shutdown and boot (NOT reboot) at a specific time during the week.
I did a lot of researches but I have't found the answer to my question. Everybody says that's impossible to boot using a timer since the device is supposed to be off. However, in the settings of the device, there is an option "Timer Switch Machine" which allow to do that (as describe in the link above). So I think there is a way to hack this functionality throw my app, if the device is rooted. But I don't know how to do that.
Does anyone have an idea?
This functionality is not part of the AOSP. That means first you have to gain access to the source code (or alternatively talk to someone who has access to it).
You might be able to find the corresponding code by decompiling System apps (especially the app which contains the option).
Otherwise you'd have to find a contact to the developer (probably via the manufacturer).
If you have the sources, the easiest way to hook into it is normally using xposed.
But depending on the actual implementation (e.g. if it's a shell call) there might be a better way.

Explicitly Managing WiFi Power Consumption in Android

Background
I'm developing a research application that runs on Android phones. In short, the application runs so long as the phone is on and periodically takes information from many components and sensors on the phone. The application is to disturb the user as little as possible. That being said, it's draining the battery far too quickly and forces the user to recharge every day. This simply won't do.
To try and figure out how to improve the situation, a colleague also working on the application let the application run for a long period of time and noticed that the biggest battery hog is WiFi. My current idea is to manually shut off WiFi when it's not in use in an attempt to save power. AFAIK, Android uses PSM for WiFi to accomplish this to some end, but it doesn't seem to be enough.
Problem
Is there a way to "ramp up" Android's PSM? Or, if there is not as this question suggests, is there any way that I can safely turn WiFi on and off without adversely affecting the user? I.e., is there a way to tell which applications are using WiFi and turn it off when none are? Do standard applications - such as the web browser and email clients - use WiFi locks to prevent WiFi from being turned off when they are working?
Any advice on where to start in solving this problem are greatly appreciated. Information on how Android's PSM works, how long it takes for it to take effect, or any information relevant to the problem are very welcome.
Thanks for your time!
Is there a way to "ramp up" Android's PSM?
Not via the Android SDK.
I.e., is there a way to tell which applications are using WiFi and turn it off when none are?
The OS does this already.
Do standard applications - such as the web browser and email clients - use WiFi locks to prevent WiFi from being turned off when they are working?
Some probably do. You are welcome to search the Android source code and find out. Of course, bear in mind that there are no "standard applications" -- I presume you are thinking of the ones that are part of the Android open source project.
Any advice on where to start in solving this problem are greatly appreciated.
Find out where in your own code you are being inefficient, specifically here:
the application runs so long as the phone is on and periodically takes information from many components and sensors on the phone.
If the device behaves fine when your code is not running, and the device does not behave fine when your code is running, then the problem lies in your code. Conversely, if the device does not behave fine even when your code is not running, then something else is afoot (device defect, firmware defect, rogue application, etc.), but it probably has nothing to do with StackOverflow.

How to stop an android device from being charged programmatically?

Is there an Android API for stop charging even though physically the charging is on?
Reading previous answers, it looks like there's no way to do this exclusively in software. However, it should be relatively easy to do it with a little hardware help - i.e. by using any Bluetooth- or WiFi-enabled smart electrical switch with open API. The phone could then switch the charger on or off programmatically whenever it feels like it.
Is there an Android API for stop charging even though physically the charging is on?
AFAIK no.
Justification:
android.intent.action.BATTERY_CHANGED is a protected intent that can only be sent by the system. Therefore you cannot duplicate or override the functionality.
You guys are all missing the point - the purpose of limiting charging is to increase battery lifespan by keeping it away from fully charged conditions (and near empty but that's a different issue). If you anticipate needing a full charge then tell it to charge to 100.
If you can't set a charge limit then the battery would rarely be idle and ideally charged when on the charger. It probably requires device level support though.
https://play.google.com/store/apps/details?id=es.guille.stopcharge uses echo "0" > /sys/class/power_supply/battery/device/charge. It works for me on a nexus 4 (rooted), as long as the device isn't fully charged (in a charging state).
Also relevant: https://android.stackexchange.com/questions/15001/how-can-i-avoid-the-battery-charging-when-connected-via-usb
Contrary to some answers indicating it's not possible, it is, indeed possible with ROOT. You can find some apps on the Play Store that will allow you to do this (with root permission, of course).
The best app that works on every phone I've tried it on is Battery Charge Limit. You can download it from the Play Store or the XDA discussion thread. The app is under active development so, if you find that your phone isn't supported, just submit an issue on its GitHub page.
NB: I am not the developer of this application.
This is unfortunately not possible. Android only have read APIs for battery data.
Battery charging control is internal to the Android kernel and battery IC modules. Manufacturers do change it from time to time, like HTC is having small cycles from 95-100% (a bad idea IMO), Samsung does stop charges as soon as it reaches 100%, but I've never seen a device able to stop charging before 100% to reduce battery aging :(.
At best if we're lucky, a sysfs interface might help do that, but it requires root and will differ from device to device.
Just to add to this. Samsung phones do not stop charging after 100%. As far as I'm aware they "trickle" charge past this point however they recommend you do not charge your phone past 100% for over 1 hour. Battery manufacturers like Anker also state the same so the idea of stopping the charge at 100% would be really useful. The risks of leaving the phone on charge are battery bloat and eventually cell rupture. I wasn't aware of this to start off with an killed my samsung battery within 3 months of owning the phone.
To expand on the original question. I've noticed some kernels allow fast charging. If they are able to alter the charge rate up could we alter the charge rate down (trickle) to meet a desired finish time (when your morning alarm goes off)??
I have installed a timer on the AC receptacle where I plug my Moto E's charger into. After guestimating how much time the battery needs to charge to about 85%, I set the timer. This is not my idea of a solution, but at least it keeps my phone from being charged to 100%, as I usually err on the short side when setting the timer.
I dont think there would be such an api. If it does exist it needs to be supported by the device manufacture as its not a pure OS lever feature. The same reason would make it a bad idea to use it as not all devices will support it.
That being said it would be a bad idea to use/implement it , mobile devices are not built to directly run from the power supply and a user will not plug in the cable if he/she did not want to actually charge the device.

Categories

Resources