Sending simple text to Macrodroid

1,244 views
Skip to first unread message

Simon Davison

unread,
May 8, 2021, 7:48:33 PM5/8/21
to DroidScript
Hi DS,  I'm scratching my head a little trying to fathom sending and receiving simple text to and from a macro in Macrodroid.  

I've looked carefully at the send and receive intents examples together with the send file example which also uses intents.  The latter is interesting as there is a simple text intent going on there which looks easy enough.  

I gather I have to change the "packageName" to the com.arlosoft.macrodroid.  I've nulled the category as I wish the action to be explicitly for a a macro, so no broadcasting.

Does the action name have to stay exactly the same together with the extra name (TEXT) or can they be literally anything?

I'm struggling to receive the intent in macrodroid as I'm not precisely sure what the naming of the action and extra fields need to be, single names or the OO expression names as seen in the droidscript example.

What would macrodroids send intent have to look like to get text through to droidscript too?

Any help will be appreciated.

Code as follows:-

//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" )

//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Send Intent", 0.3, 0.1 )
btn.SetOnTouch( btnTxt_OnTouch )
lay.AddChild( btn )

//Add layout to app.
app.AddLayout( lay )
}

//Send text to Macrodroid.
function btnTxt_OnTouch()
{
    var textData = "The cat sat on the mat";
    var packageName = "com.arlosoft.macrodroid";  // Changed for Macrodroid
    var className = null;
    var action = "android.intent.action.SEND";
    var category = null; // "android.intent.category.DEFAULT";  nulled so as not to broadcast to share sheet
    var uri = null;
    var type = "text/plain";
    var extras = [
        {name:"android.intent.extra.TEXT", type:"string", value:textData},
    ];

    extras = JSON.stringify( extras )
    app.SendIntent(packageName, className, action, category, uri, type, extras)
}



Alan Hendry

unread,
May 11, 2021, 12:31:26 PM5/11/21
to DroidScript
Hi,
Developers seem to include the ability to receive intents, but they seldom document how to use them.
DroidScript app.GetActivities() should give you the Classname and Packagename.
I presume you've seen
(Includes examples of sending intents, and receiving broadcasts).  
Regards, ah 

Simon Davison

unread,
May 11, 2021, 12:46:36 PM5/11/21
to DroidScript
Hi, Thanks for your reply.  Yes, I've seen those extra examples but they are all for other apps and predetermined.  I think I might be trying to do something which is not possible.  I'm under the impression that a DS SendIntent function is actually conjuring up a unique intent which I am expecting MD to react to, whereas SendIntent can only work with a program's predefined activities.

I wonder if using intents is over complicating the task.  Is there a better way to send text from DS to MD?  I'm really looking for any (discreet?) way to get text directly into MD.  The only other way I can think of is to get DS to send the text as a notification which MD can pick up, but it seems a bit insecure compared to an explicit intent knocking directly on MD's door.   

Regards,
SD
Message has been deleted
Message has been deleted

Dave

unread,
May 14, 2021, 6:12:01 AM5/14/21
to DroidScript
Great.  It would be good if you could share your solution here so other won't have to struggle with the same problem in the future.  Thanks
Reply all
Reply to author
Forward
0 new messages