Learning about Broadcasts and Intents

Post your questions and help other users.

Moderator: Martin

Post Reply
skiptannen
Posts: 82
Joined: 13 Jan 2014 21:39

Learning about Broadcasts and Intents

Post by skiptannen » 16 Oct 2017 21:20

I'm trying to understand how to use broadcasts and intents, partly just to learn how they work and partly to see how I might be able to use them in flows, but I'm having trouble figuring it out. I probably should be digging into the Android documentation but since I'm not a programmer I figure it's all going to be way over my head.

I was thinking that I could get a handle on it if I had a flow using the trigger General Broadcast and had it log all the captured variables to a text file, but I haven't been able to figure out how to configure the trigger to capture all broadcasts. Thinking I could use a wildcard, I tried setting up the trigger with an asterisk in the Action field and with action = getString("action") in the Access Intent Extras field. I used different apps and did different things on the phone for a while, but the trigger never fires.

Is it possible to capture all broadcasts, and if so, how do I set up the trigger?

Thanks in advance.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Learning about Broadcasts and Intents

Post by Desmanto » 17 Oct 2017 16:00

You can't use asterisk to match all broadcast there. It must specific to certain broadcast. Most of the specific one should be provided in documentation by the dev of the app.

Actually most of the useful general broadcast has been covered into triggers in Automagic. As you can check some of them : Trigger Airplane Mode, actually derived from General Broadcast android.intent.action.AIRPLANE_MODE. There are a lot like this example. You can see most of the trigger in automagic actually can be found in the General broadcast action.

If you want to capture the broadcast real time, you have to use logcat. Use adb in PC, if you don't have root. You need to use verbose output and filter for keyword "intent". This will list all possible intent in real time, not limited to broadcast, but including activity and service as well. Some has {extras} which can't be seen in the logcat. (I would like to know how to check for the {extras} value as well)

To only list all possible broadcast at your phone (with all your current installed app), use dumpsys in adb at PC

Code: Select all

adb shell dumpsys activity broadcasts > C:\broadcast.txt 2>&1
If you have root, you can just directly use execute root command.

Code: Select all

dumpsys activity broadcasts
Write file the {stdout} to file.

There you can see tons of available general broadcast. It will surely overwhelm us with too many information. I plan to make a script to parse the information for the most useful one. But currently I just parse it in excel for better view and filtering. There are some historical broadcast those can be checked as well.

But if you mean to know more about sending intent (especially share), you can read example at my index. Send Intent
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

skiptannen
Posts: 82
Joined: 13 Jan 2014 21:39

Re: Learning about Broadcasts and Intents

Post by skiptannen » 17 Oct 2017 18:15

Thanks Desmanto - as usual, a very detailed response with helpful information. Much appreciated.

I've never played with adb or dumpsys, but it sounds like those commands would be useful, and it should be easy to grab the dumps using your instructions.

As for intents, I had seen your post a couple of months ago and was disappointed to find that the app Intrications was not available in the US Play Store. I did find a few other utilities that purport to expose intent details but I have not tried any of them yet. My concern is that those kinds of utils will only show the raw information but don't really explain what you're looking at. I'll probably give them a try once I get into it and learn a little more.

Thanks again.
Desmanto wrote:You can't use asterisk to match all broadcast there. It must specific to certain broadcast. Most of the specific one should be provided in documentation by the dev of the app.

Actually most of the useful general broadcast has been covered into triggers in Automagic. As you can check some of them : Trigger Airplane Mode, actually derived from General Broadcast android.intent.action.AIRPLANE_MODE. There are a lot like this example. You can see most of the trigger in automagic actually can be found in the General broadcast action.

If you want to capture the broadcast real time, you have to use logcat. Use adb in PC, if you don't have root. You need to use verbose output and filter for keyword "intent". This will list all possible intent in real time, not limited to broadcast, but including activity and service as well. Some has {extras} which can't be seen in the logcat. (I would like to know how to check for the {extras} value as well)

To only list all possible broadcast at your phone (with all your current installed app), use dumpsys in adb at PC

Code: Select all

adb shell dumpsys activity broadcasts > C:\broadcast.txt 2>&1
If you have root, you can just directly use execute root command.

Code: Select all

dumpsys activity broadcasts
Write file the {stdout} to file.

There you can see tons of available general broadcast. It will surely overwhelm us with too many information. I plan to make a script to parse the information for the most useful one. But currently I just parse it in excel for better view and filtering. There are some historical broadcast those can be checked as well.

But if you mean to know more about sending intent (especially share), you can read example at my index. Send Intent

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Learning about Broadcasts and Intents

Post by Desmanto » 18 Oct 2017 16:49

I also just found out how useful dumpsys is. You can use dumpsys -l to list all possible command.

Intents are in the area of developer. We as users just simply can improvise, adapt, overcome. There is no explanation, there are only a few manual guides. Usually I will just google the syntax or any suspicious term, to check if there are examples of usage out there. Then I simply test it out using debug dialog until it works, kinda like banging the head to the wall until the door open. :D

The bright side is the intents always fall under certain category, with certain parameter. After using it several time, we usually can recognize the pattern intuitively. Martin has listed some of the example of intent usage. viewtopic.php?f=5&t=1880

I will try to add mine too maybe if I can find some time (and mood) to lists all the start activity I am using.

For Intent intercept, you can try to download from F-Droid.
https://f-droid.org/packages/uk.co.asht ... intercept/
AFAIK it is open source and F-Droid simply rebuild it and signed the apk using their signature.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

skiptannen
Posts: 82
Joined: 13 Jan 2014 21:39

Re: Learning about Broadcasts and Intents

Post by skiptannen » 20 Oct 2017 09:23

Ha! I do feel like I'm banging my head but that door never opens very wide! :D

I should try Intent Intercept - it might be better than digging into Android directly. I am making a bit of progress capturing intent information using logcat, but so far I'm not seeing much that's app related. Maybe I just don't know what I'm looking for. I've figured out how to filter logcat entries for intents by using the command:

logcat | /system/bin/fgrep -i intent

but like I said, I need to learn more about what I'm seeing...
Desmanto wrote:I also just found out how useful dumpsys is. You can use dumpsys -l to list all possible command.

Intents are in the area of developer. We as users just simply can improvise, adapt, overcome. There is no explanation, there are only a few manual guides. Usually I will just google the syntax or any suspicious term, to check if there are examples of usage out there. Then I simply test it out using debug dialog until it works, kinda like banging the head to the wall until the door open. :D

The bright side is the intents always fall under certain category, with certain parameter. After using it several time, we usually can recognize the pattern intuitively. Martin has listed some of the example of intent usage. viewtopic.php?f=5&t=1880

I will try to add mine too maybe if I can find some time (and mood) to lists all the start activity I am using.

For Intent intercept, you can try to download from F-Droid.
https://f-droid.org/packages/uk.co.asht ... intercept/
AFAIK it is open source and F-Droid simply rebuild it and signed the apk using their signature.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Learning about Broadcasts and Intents

Post by Desmanto » 20 Oct 2017 14:36

Keep banging, eventually the wall will crack or our head will crack first : :D

Just kidding. Sometimes we have to retreat and rest for a while. Let the information sink first, and revisited it several hours or days later. As the saying, as we grow older we get wiser. Leave the problem for the wiser version of us :lol:
I don't finish the flow all at once. Sometimes I just leave it alone when stuck, play some game, listen to music, keep busy with work. And when I am doing other things and later came back, somehow new inspiration appear and I will test it again until success or stuck again. Repeat the process.

Intent intercept is very useful. I've just shared the rename flow viewtopic.php?f=3&t=7037
I used intent intercept to get what automagic send when it shares the flow/widget. Simply share the flow to intent intercept, it will reveal parameter needed to replicate the same share.
You can match the data in intercept with what I put at the extras in Start Activity element of the flow.

Logcat with filter keyword "intent" will work too. But it is too general, as it will catch all, activity, service, and broadcast. Overloaded with too many information. While Intent intercept will mostly catch the intent send/share or open, which are usually the most useful ones. It will be easier to start with the send/share intent first.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply