Location, Wifi, Bluetooth toggle widgets

40bpm

New member
I feel somewhat arrogant posting my code for the entire macrodroid world to see. I am not an expert and I write code as entertainment in my old age.

These macros were created to:
  • Indicate the state of Location, Wifi and Bluetooth at a glance on my home screen.
  • Provide Home screen, one-touch control of Bluetooth, Wifi and Location.
  • A single “All On” / “All Off” widget button to rule them all, including Airplane Mode toggling.
  • Read a screen or the Status Bar and click your choice.
  • Automate control of battery charging.

Screenshots are paired for readability and to conserve space, and don’t necessarily indicate a sequence.

The Home screen showing the widget buttons before and after:
1683198338936.png

"Charge Me" is an example of how I use the macros to control battery charging.
The extra battery % bounds take care of situations where the process is interrupted or fails to complete the first time.
Crude, and it might work some of the time for some people.
1683198381494.png


Global variables as set by the previous execution. The “clickWhichArray” is a DictionaryArray and contains the result of reading the screen after expanding the Status Bar (or any screen). Run the macro once and look in the “clickWhichArray” to find the name of the target and use it as the “clickWhich” value.

The use of “*” allows the same code to be used for both the “On” and “Off” values to toggle.
1683198484654.png


“Clickerator” can be used anywhere to search a dictionary array, find your choice and click on it.
It works for any screen after executing “Read Screen Contents”. In these examples, I use it to read the Status Bar values.
“Clickerator” will search the “clickWhichArray” for the Global Variable “clickWhich” and click on it.

“Toggle All” does exactly that, and updates the “Toggle All” widget.
I was unable to toggle reliably without the “IF” statement.
It seems the sequence of toggling is important, especially the finicky Airplane Mode, Wifi and Location selections.
I use the “Toggle All” in any macros that need the functionality.
The “Expand Status Bar” exposes the controls. Adjust the “Collapse Status Bar” to accomodate your sensibilities.
1683198559700.png


“Toggle Bluetooth” can be modified to meet your needs.
“Toggle Bluetooth 2” updates the Bluetooth widget button on the Home screen.
I find the single touch Bluetooth widget on my home screen especially useful.
1683198628318.png


“Toggle Wifi” has a “wait” loop because I had trouble using a "wait for event" trigger. It also ensures that Wifi is on, connected and ready.
“Toggle Wifi 2” updates the Wifi widget button on the Home screen.
1683198646112.png

“Toggle Location” by reading the expanded Status Bar and calling the “Clickerator” macro.
“Toggle Location 2” updates the Location widget button on the Home screen.
1683198675590.png

This mess of macros works on my two Samsung S9 phones (Android 10) and a Samsung A7 tablet (Android 11), each with their own charger and smart plug. No root and no ADB Hack required.

I don’t know how to upload the code to ensure that all the pieces hang together.

I’m an ancient COBOL programmer, so pardon my BFI (Brute Force and Ignorance) methodology.

Improvements and suggestions are welcome.
 
Last edited:

fmcpma

Member
Hello.

To upload your macros, you should use the Templates option at the bottom of MacroDroid's home screen and then the Upload icon – the one with the cloud and the up arrow.

Good luck.

P. S. – I also took a course in Cobol (and RPG). But I never used any of them when I got a job.
 
Top