Use Intent Broadcasts to communicate inside MacroDroid [ideas]

FrameXX

Well-known member
I am sure everyone knows "Macro Run" action or use variables to trigger another macros, but I think sending an Intent broadcast is another good way how to communicate inside MacroDroid that is not much used.

Using intents is not good for storing values like variables do, but rather for triggering events. Unlike with "Macro Run" action you can recognize that intent was fired and not some other trigger.

You can also trigger with some extra data by adding an extras into intent action and than receiving them.

For example I can run a Macro that will do something and than it will need to decode some text. But the text will be decoded by some another macro. I can use send intent action to fire that macro and also send extra with text I want to decode. Macro does it's work and than sends back intent with decoded text. My macro used wait until trigger and now it continues with text decoded. No global variables needed! What a Magic!

So why not use Variables instead? They can do all of this.
In case of just triggering something and not storing values, I don't see a reason to use variables and messing up your global variable list even more. It's lot simpler to use intents in this scenario.

HOW TO SEND A BROADCAST INTENT
Target:
Broadcast
Action: You can name it as you want, just don't use spaces and other special characters (MyIntentBroadcast)
Package: You don't need to write package, but I recommend you to do it, otherwise all apps will be able to see the broadcast (com.arlosoft.macrodroid)
Extras: Name your extras as you want and add some variable as a value. (MyVariable; [lv=MyVariable])

HOW TO RECEIVE A BROADCAST INTENT
Action:
Name of action you sent (MyIntentBroadcast)
Extra name: Name of your extra (MyVariable)
Extra value: Value to match. You can use * all the time, which will match any text. But for example *5G* will only match if text contains 5G. If extra value will not match, trigger with intent will not fire at all.

HINT: If you receive intent with extra it's possible, that it will receive and fire many times in 1 time. To prevent this kind of spamming add "This macro not invoke for 1 second" constraint for intent trigger. I think this is a MacroDroid Bug 😥.
 
Last edited:

Mr.Lon

New member
So!....how would an intent to switch mobile data look like? I'm asking because neither the parameters in global systemtable nor the normal actions in MacroDroid are working properly in MiUi 12 with Android 11. Thx for reply
 

FrameXX

Well-known member
So!....how would an intent to switch mobile data look like? I'm asking because neither the parameters in global systemtable nor the normal actions in MacroDroid are working properly in MiUi 12 with Android 11. Thx for reply
Intents I mean itself does not do any actions. They are only used to communicate between MacroDroid macros in my idea. You can't turn ON or OFF with intents. In that way every app would be able to control your mobile data.
 

Elenkhos

Member
So why not use Variables instead? They can do all of this.
In case of just triggering something and not storing values, I don't see a reason to use variables and messing up your global variable list even more. It's lot simpler to use intents in this scenario.
The main reason I'm using triggers to invoke macros (named with T_MacroName) is that it's easy to find all the macros that can trigger a specific macro. Sometimes this is extremely important when debugging/modifying macros. I have over 200 macros so it wouldn't be possible to manually to search all the triggering macros. I admit that global variables list is becoming quite bloated with all these trigger variables but at least they're in one group starting with T_.

Otherwise, intents are fine way to trigger other macros. Thanks for the idea!
 

dsnz

Well-known member
I think a macro run is internal, simpler and better for your battery (and way faster), but yes intents are sexy (😂).

@FrameXX indeed you wrote with detail on how to use intents , but it would be better if you posted simple example macros to illustrate how to program with intents.
 

FrameXX

Well-known member
I think a macro run is internal, simpler and better for your battery (and way faster)
I am not any kind of expert but I think intents are send in android essentialy all the time in background and few intents from MacroDroid shouldn't make no real difference in battery life. About speed, intents inside android should be (and I think they really are) basically instant, but of course "macro run" action could be more reliable.

but yes intents are sexy
YES.
 

sjmd

New member
I used the information above to do something very useful.

I have a load of large tubs outdoors which have lids which are a pain to remove. I wanted to put an NFC tag under each lid which when scanned would trigger macrodroid into showing me an image of what was inside the tub.

The NFC tag doesn't hold any identification data such as text for a filename, but rather I used it's own serial number (when scanned with NFC Tasks) as the data it passed to MD.

This worked great and more importantly instantly. It certainly felt like magic.

The only obstacle now is manually creating the dictionary in macrodroid that uses the serial numbers (passed in an intent from the NFC tag) as the key and the filename of the photo that is to be shown. At the moment this is done by creating a CSV file in another app and using the Shell Script in MD to cat the file into an MD string variable where I do a s**t ton of regex filtering to get the data I want.

I found a fab app called Qess std/pro which is like a spreadsheet but has the ability to make custom data entry keyboards which can even be used to execute JavaScript! I've sent the developer a couple of emails begging him to consider being able to send/receive broadcast intents so I can create a direct link with MD instead of using cat in a shell script.

He is considering implementing it, but it could be a while. In the meantime, give Qess a look as it's completely awesome.
 
Top