Android activate and deactivate standby mode from the app - android

I have an app which runs in my company without user interaction. It is just a monitoring of current company processes. The devices are not portable, I am using android boxes with hdmi monitors. The devices are so configured that they never go in standby. I want that the android box goes standby on a certain time and wake up on a certain time without user interaction. Is this possible from my code? Or is there an app that will do this for me?
Best regards,
Peter

Related

Android: how to execute service when nearby found some ble device

Right now I'm developing client application for Android that works with physical locks with our controllers. User can open lock via Bluetooth using this application (connection -> secure session creation -> sending some user key).
All works fine except one feature: opening lock when Android device screen is off.
I am using following approach:
Foreground service that periodically scans for nearby BLE devices and when scan is successful (nearby lock device found using BLE filters), application tries to connect and send lock key to lock device.
So, there are two problems:
Android kills foreground service in few minutes after screen off. After setting ignore battery optimization it works ok, however I can't find universal way to navigate user to those settings (because those settings are vendor specific, see https://dontkillmyapp.com/ and android open battery settings programically).
Background limits for BLE scanning are tricky.
I know one application that achieved same thing without foreground service: https://play.google.com/store/apps/details?id=eu.hoermann.ast.bluesecur, this application seems to work good in background without user interaction with battery usage optimization menu.
So, question is:
what is the best way to trigger background process (device screen is turned off) when nearby suitable BLE device available?
Your requirements perfectly describe the scenario of a companion app. Disadvantage: it is only available from Android 12 (API level 31) onwards.
I think you shoul add a wake lock with the service:
https://developer.android.com/training/scheduling/wakelock
https://developer.android.com/training/scheduling/wakelock#cpu

is there any way to continue Bluetooth Low Energy scan,never stop for a android app

I 'm developping a continue scan android app, because I have to collect some important info from another device , I have to scan ble device,and never stop, otherwise, I may miss some important info. Is there any way for a android app to continue Bluetooth Low Energy scan,never stop ,scan for a year if the important device don't appear. During the year, my android phone always keep sufficient electricity,but sometimes I will press home button , sometimes I will make Screen Off (not power off ,just make screen off).
Modern Android has implemented various battery saving measures which will prevent you from continuous data collection.
Doze mode is implemented by the Android framework. See: Scanning for Bluetooth LE devices when the phone is in doze mode, don't work. CallBack method doesn't called when doze mode
Additionally various device manufacturers have implemented their own battery savings systems which will kill your app even when you are following Android framework rules. See: https://dontkillmyapp.com/ for details.

Turn on the device automatically

I want to develop an application that has auto-power on when the device is off.
There is a way to set your device to automatic power on? like a scheduled task?
"I want to develop an application that has auto-power on when the device is off."
Answer: This is impossible. You can't run code on a device which is turned Off.
If it would be possible, every anti-theft App would have something like that to track the phone.

Can a BLE peripheral connect to a background app on an Android phone?

I am working on an application where we will have a BLE peripheral with a button, and an App running on an Android phone. The user will manually pair the peripheral with the phone, and then the phone may go into standby, or be used for other purposes.
Can a button press on the BLE peripheral cause the phone to wakeup and open the App?
On a related note, if the phone is power cycled, can it be configured to automatically re-pair with the peripheral, without requiring any user action?
If the peripheral is power cycled, can it automatically re-pair with the phone, without requiring any user action?
All the answers are YES , with some custom algorithms.
However I have to remind that in Android 4.3, connecting without user interaction is extremely dangerous. Android 4.3 cannot cancel any outgoing connection due to a bug, and no callbacks for connection time out. If the peripheral goes out of range/ runs out of battery / simply malfunctions during the connection, the Bluetooth stack of your phone will just STUCK until you reboot your phone.
If the connection is initiate by the user in the ui we can alert the user when it gets wrong, but if you start connection in the background automatically you may risk in breaking the Bluetooth without user understanding whats going on.

Can an application on Android phone be updated in sleep mode?

There are 3 states an Android phone can be in: Awake, Asleep and Off. See: Android: Sleep stages/levels on an Android device?
In sleep mode screen goes off, CPU shuts down along with Wi-Fi and GPS radios. See: http://developer.android.com/reference/android/os/PowerManager.html and Android Sleep/Standby Mode
But GSM or CDMA radio still works and the device can receive incoming calls, SMSes, and IP packets. Also, Google introduced new Google Cloud Messaging service that sends data to devices and can, as I understood, wake the device if necessary. See: http://developer.android.com/guide/google/gcm/index.html
So, my question is: can application on Android device be updated via Google Play if the device is in sleep mode? I mean is Google Play allowed to receive some kind of messages from the cloud, wake the device and update applications? I assume that the application is allowed to be updated automatically and can be updated through mobile network (3G/4G).
Thank you.
UPDATE: I did some research and it happens that Nippey's answer and comments are correct. I did not see any updates to wake my device but as soon as the device is awake updating mechanism starts to work normally. So, theoretically, Google Play Store can start updating your applications right after the device wake up.
The device is able to process push-messages while in sleep mode.
As soon as you trigger an update via the play.google.com, this will issue a push request, which, as a consequence will wake up your device. The update will be installed immediately.
So, it doesn't work in sleep mode, but if the device gets a trigger to wake up, it will do what has to be done.

Categories

Resources