Use Intent Broadcasts to communicate inside MacroDroid [ideas]

FrameXX

Active 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

Active 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

Active 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

Active 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.
 
Top