Using automate:// URI scheme to perform actions in flows

989 views
Skip to first unread message

Thomas Nijssen

unread,
Apr 4, 2021, 6:41:11 PM4/4/21
to automa...@googlegroups.com

Looking at the manifest, I see that Automate is capable of listening to automate:// URLs.

In particular, com.llamalab.automate.LocalBroadcastActivity has this intent filter:

<intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="automate"/>
</intent-filter>

My theory is that I can make a flow with a broadcast receiver that waits for some specific URI of that format to be called to do an action.

To try it, I call the following:

adb shell am start -a android.intent.action.VIEW -d automate://asdf?something=123456 -f 8

It sort of works, since I can see some output in logcat from the LocalBroadcastManager from androidx:

04-04 15:04:58.406 15255  7168 V IntentResolver: Scheme list: [ActivityIntentInfo{5ae9e2f com.llamalab.automate/.LocalBroadcastActivity}, null]
04-04 15:04:58.406 15255  7168 V IntentResolver: Matching against filter ActivityIntentInfo{5ae9e2f com.llamalab.automate/.LocalBroadcastActivity}
04-04 15:04:58.406 15255  7168 V IntentResolver:     141c0bc com.llamalab.automate/.LocalBroadcastActivity filter 5ae9e2f
04-04 15:04:58.406 15255  7168 V IntentResolver:   ResolveInfo{ce30a46 com.llamalab.automate/.LocalBroadcastActivity m=0x208000}
04-04 15:04:58.408 15255  7168 I ActivityManager: START u0 {act=android.intent.action.VIEW dat=automate://asdf?something=123456 flg=0x10000008 cmp=com.llamalab.automate/.LocalBroadcastActivity} from uid 2000
04-04 15:04:58.408 15255  7168 V IntentResolver: Resolving type=null scheme=automate defaultOnly=false userId=0 of Intent { act=android.intent.action.VIEW dat=automate://asdf?something=123456 flg=0x10000008 cmp=com.llamalab.automate/.LocalBroadcastActivity }
04-04 15:04:58.421 16224 16224 V LocalBroadcastManager: Resolving type null scheme automate of intent Intent { act=android.intent.action.VIEW dat=automate://asdf?something=123456 flg=0x10800008 cmp=com.llamalab.automate/.LocalBroadcastActivity }

That last line is enabled by doing `adb shell setprop log.tag.LocalBroadcastManager VERBOSE` and having that flag value of 8 earlier.

However, my broadcast receiver does not proceed.

My question is: what is the way to use this functionality and accomplish my use case?


Henrik "The Developer" Lindqvist

unread,
Apr 4, 2021, 8:01:53 PM4/4/21
to Automate
That's an unofficial/undocumented feature to let a browser send an URL to a flow awaiting it with a Broadcast receive block.

There's no need to use that URI scheme, i.e. automate://, if you wish to send broadcast to a flow, just use any custom action, e.g:
adb shell am broadcast -a com.example.action.FOOBAR

What is the use-case?

thomasn...@gmail.com

unread,
Apr 5, 2021, 1:58:38 PM4/5/21
to Automate
My particular use is to workaround the issue in the other thread (web dialog window having 0 height) for an OAuth login. The service I'm trying to use does seem to allow for a custom URI scheme for the redirect URI. So I was thinking of setting the redirect URI to be something like "automate://oauth_callback?code=...".

As you saw from my initial message I am able to use the "am broadcast" technique already.

Henrik "The Developer" Lindqvist

unread,
Apr 5, 2021, 2:16:34 PM4/5/21
to Automate
That might be possible, but i suspect that redirects aren't resolved using the Android intent system.

Your call was using "am start ..." which is used for starting an Activity, e.g. com.llamalab.automate.LocalBroadcastActivity, while "am broadcast ..." is for sending broadcasts directly to the Broadcast receive block.

Thomas Nijssen

unread,
Apr 5, 2021, 7:04:29 PM4/5/21
to automa...@googlegroups.com

I think redirects may be resolved by the intent system since (I think) app deep link services determine whether to launch the given app or send you to the Play store. I could be mistaken, however, as I have not done much app development. Maybe you have to use the intent: URI scheme? I tried that briefly and didn't get anywhere, but perhaps I did it wrong.

My usage of "am start" is actually correct since it targets an activity. When the activity is chosen to be launched (by way of another app launching a VIEW intent with the proper URI) then according to my reading of the disassembly, the LocalBroadcastManager from androidx is simply called to deliver the intent as a broadcast instead.

--
You received this message because you are subscribed to a topic in the Google Groups "Automate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/automate-user/ZjRUNgu1T3U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to automate-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/automate-user/ff31d8c5-3b41-42fb-9838-e261c0a06719n%40googlegroups.com.

Henrik "The Developer" Lindqvist

unread,
Apr 5, 2021, 10:18:07 PM4/5/21
to Automate
Chrome seems to support intent: URIs for links at least, see:

"am start ..." is indeed correct for targeting an Activity, e.g. com.llamalab.automate.LocalBroadcastActivity, but it's not necessary for simply sending a broadcast to an Automate flow, doing it directly using "am broadcast ..." is probably faster as it doesn't involve an UI.

Thomas Nijssen

unread,
Apr 5, 2021, 10:50:18 PM4/5/21
to automa...@googlegroups.com

Please find attached an example. First install the flow, then open the HTML file.

I could not get the broadcast receiver for Automate to work. The ZXing one below does work, however.

Did I miss something when crafting the URL?

Intent URLs.zip

Henrik "The Developer" Lindqvist

unread,
Apr 6, 2021, 1:09:04 PM4/6/21
to Automate
Chrome can't send broadcast, only open an Activity, so here you do need to use the automate:// URL, e.g.:
<a href="automate://asdf?blabla=123">click me</a>

Then in the Broadcast receive block:
  • Action: android.intent.action.VIEW
  • URI scheme: automate

Thomas Nijssen

unread,
Apr 6, 2021, 6:00:45 PM4/6/21
to automa...@googlegroups.com

That doesn't seem to work unfortunately.

Looking at the AndroidX source, here is where the broadcasts are actually dispatched. When I have more free time (😅) I will debug the app to try to see if this gets triggered.

Reply all
Reply to author
Forward
0 new messages