Here is an example of doing something when the the screen is off. A very important something.
At home I have a poor mobile signal, so I use WiFi calling and turn on airplane mode to make sure WiFi calling is used and to save battery.
On leaving home, the phone is usually in a pocket with the screen off, when WiFi disconnects due to distance from the router.
A macro triggers on loss of wifi, turns off airplane mode, turns on mobile data and turns off WiFi, all with the screen off. Consequently I know my phone is ready to use while I'm away from home, importantly without any user intervention.
I have other macros that are designed to run only when the screen is off, to avoid user actions potentially interfering with the macros if run with the screen on.
I have created an 'auto wifi on off' (there are plenty on Playstore) I will upload mine soonly. Then for you,
Just unlock mobile > wifi turns on automatically...
- if you are at home it will reach whatever SSID, so just use it
- if you are out of home, samely, the wifi turning on will try to reach any wifi available and give up after 15 seconds (this can be done by checking connectivity, see below). Then just turn on 'automatically' data mobile to continue.
Unfortunately, nowaday (due to google) it is impossible to turn 'automatically' data, unless on rooted mobile or ADB commands proposed by Macroid (too hassle for me).
I think to understand your need. You want to still runs some Apk, like Gmail, WhatsApp, etc... through wifi if available if not by mobile data ?
Macroid can, trigglers are (put all together):
- screen on, screen off, power plugged, unplugged, all imaginable actions you do 50 times a Day
- perhaps also a timer for every hour, or 2 ?
Actions are:
- mobile data is actually off
- turn wifi on
- check connectivity, means sending a ping to whatever server (google.com)
- if returns True (means you are at home) then continue (and confirm mobile data stays off)
- if not (you are not at home), turn off wifi and turn on mobile data... but as said, impossible nowaday, unless by ADB.
One can improve by:
- stop wifi/data after 30minuts, time to load whatever informations needed to save battery (reminder: by timer macro will work again next hour)
- keep wifi if power is plugged
Is something like that you have created ?