Trying to extract extras/bundle data from Received Intent

998 views
Skip to first unread message

Tim G

unread,
Jul 29, 2014, 4:52:25 PM7/29/14
to tas...@googlegroups.com
Not a n00b, but just a Tasker end-user and certainly not a developer here, so please talk to me like I'm five...

My question is similar to the one Matt posed a while back at http://grokbase.com/t/gg/tasker/13bmnmreyz/bundles-in-broadcast-intent-receiver

...except I'm specifically trying to capture and act on information that Android (CM11S) is broadcasting behind-the-scenes, which looks like this:

#99: act=android.intent.action.PROFILE_SELECTED flg=0x10 (has extras) 
extras: Bundle[{lastName=Bedtime, name=Home, uuid=f032ae94-5bee-4ce1-a2f3-9aa001fe39d7}]

Note: I pulled this line directly from a CyanogenMod Bug Report logfile (didn't know how else to grab it ... I'm five remember?)!  The process related to this log entry was me choosing the CM Profile I named "Bedtime" from the Quick Panel in CyanogenMod's UI.  Pretty straightforward action, but NOT easy to get Tasker to respond to!

My ultimate goal is to:
(a) Create a Tasker profile that fires when the android.intent.action.PROFILE_SELECTED action transpires; (DONE!)
(b) Use the value of name= in the "extras bundle" (words I never heard before today, mind you!) in a task. (FAIL!)

I have accomplished Step (a) by using a Received Intent : android.intent.action.profile_selected (all lower case).  That took me a day-and-a-half to Google.
However, I have no earthly idea how to parse the rest of the "junk" I'm seeing in the text sample above.  Another day of Googling turned up only Dev stuff.

I'm not writing code or an app; I just need a Task to do something useful like show the name of the CM Profile I selected (e.g. Alert > Flash > %name).
In an ideal world, I would use some logic based on the actual value of variable %name such that Tasker then fires a correspondingly-named Task.

Can anyone point me in the right direction, please?  My phone is rooted, and I have some lovely plug-ins installed (Secure Settings, utter!, NFC ReTag, etc.), so I can probably "try" anything you suggest.

MEGA-THANKS! --

Tim G the quasi-n00b

Bob Hansen

unread,
Jul 29, 2014, 5:07:26 PM7/29/14
to tas...@googlegroups.com
Use the Variable Search Replace action something like this.
It will return the name= value.

parse (360)
        A1: Variable Set [ Name:%data To:#99: act=android.intent.action.PROFILE_SELECTED flg=0x10 (has extras) 
extras: Bundle[{lastName=Bedtime, name=Home, uuid=f032ae94-5bee-4ce1-a2f3-9aa001fe39d7} Do Maths:Off Append:Off ]
        A2: Variable Search Replace [ Variable:%data Search:(?<=name=).+(?=,) Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%match Replace Matches:Off Replace With: ]
        A3: Flash [ Text:%match(1) Long:Off ]

Tim G

unread,
Jul 29, 2014, 5:24:35 PM7/29/14
to tas...@googlegroups.com
Trying hard to grok what you are suggestion (thanks, by the way)...

I think an FYI is in order here:  The text snippet I cut-and-pasted from the log file is not something Tasker has (nor will have) purview over. I just culled it to show the activity that's going on in the Android system whenever I select a CM Profile on my phone.

And, yes, I've read https://groups.google.com/forum/#!searchin/tasker/extras/tasker/qdhJhJ8ksHk/2HKwotgjiAMJ and now (finally, per Pent's own suggestion) the Userguide: 'Intents' section, but came up dry on how to proceed.

Back to your suggestion:

Looks like you're proposing I (Tasker?) run a REGEX-type string match, but as I mention above, the source string will not be present under normal circumstances (that I know of).

  - Tim



--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/VPTGbRz97fw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Matt R

unread,
Jul 29, 2014, 9:16:37 PM7/29/14
to tas...@googlegroups.com
I'll have to look back where I used it to recall the exact syntax, but I think it should just be available as %name (in the task triggered by the intent received profile).  If it's not just %name, you can turn on SD logging (in the Tasker preferences), wait for the intent to be received, then check in the log file.  It will stipulate what the received extras were and the variable names they were assigned to.  The log file can get big fast so I would recommend opening in a text editor with a search feature.

Matt

nanobrain

unread,
Jul 29, 2014, 9:48:09 PM7/29/14
to tas...@googlegroups.com
A totally different approach would be to use the "Profile 4 Tasker" plugin: https://play.google.com/store/apps/details?id=com.martinutils.profiletasker&hl=en . It adds a condition/state you can use to detect what CM profile is active. And it's only 99 cents (at least that's what I paid many moons ago) 

Disclaimer: I myself have never used this as my use of CM predates this functionality so I can't guarantee that it works, but it's worth looking into. 

Tim G

unread,
Jul 30, 2014, 9:54:05 AM7/30/14
to tas...@googlegroups.com
Toward the same end, I paid ($1.99) for the "CM Profiles for Tasker" app before I had posted this thread, and dare say the app only permits Tasker to change the CyanogenMod Profiles; it does not (from what I can tell, at least) work in the opposite direction.  I dropped a note to the Dev to inquire.  Perhaps the app you are recommending can already provide the needed "state" for Tasker to respond to.

INTERESTINGLY, midway into my testing yesterday of the very Tasker Profile and Task that originally worked in response to me changing the CM Profile...

...it STOPPED working. Somehow Tasker (or something else I did) made it so it will no longer be triggered by me picking "Bedtime" or "Home" nor any other CM Profile.

Here's the Profile:

PROFILE
Trigger: Intent Received
Action: android.intent.action.profile_selected

TASK
Flash: Done

So simple, and it worked 20x in a row yesterday, then all of a sudden stopped. Tasker really eats my lunch!! (The Flash at least had worked with plain text.)

What did NOT work, of course, was during those 20 test runs, NONE of the following produced output in the Flash:

%name
%Name
%NAME
%a_name
\%name
etc.

Tim G

unread,
Jul 30, 2014, 10:01:22 AM7/30/14
to tas...@googlegroups.com
EDIT: The Profiles4Tasker app evidently suffers the same shortcoming (of not providing a Tasker-ready state or event), as told by at least two reviewers:

" It does its job. It lets a tasker task set the profile. Would rate 5 stars if it included a State and Event for tasker, too. Maybe a future version?

"Doesn't add anything Tasker can't do. Without a variable it state for Tasker to monitor it's useless."

So, back to the drawing board for me.  This is turning out be a good, if frustrating, first major Tasker exercise for me!!

nanobrain

unread,
Jul 30, 2014, 10:38:18 AM7/30/14
to tas...@googlegroups.com
That review was from 2011, it  has been updated in Nov 2012 (granted, that doesn't give you the warm fuzzy feeling that it is continuously maintained) with the extensive change log of:

What's New
Added Condition/State.
Some UI updates to support ICS onwards

When you create a profile context check in State > plugin or Event > Plugin, Event > 3rd party.

If that turns out to be a dead end, try flashing the parameters that are in the user's guide:
  • %intent_data: the data
  • %evtprm1: the action
  • %evtprm2: the first category
  • %evtprm2: the first category
  • %evtprm3: the second category
  • %evtprm4: the URI scheme
  • %evtprm5: the MIME type
and see if anything of value shows up.

For why it stopped working all of a sudden: sometimes Tasker's queue gets filled up, maybe try and stop Tasker and restart it to get it going again?

Good luck and don't despair :)

Tim G

unread,
Jul 30, 2014, 10:57:11 AM7/30/14
to tas...@googlegroups.com
Definitely tried numerous times Disabling and re-Enabling Tasker. No love.

And I had also attempted to Flash any and all of the aforementioned variables (as written), but no go.  I think I've pissed off Tasker at this point.  :-)

But seriously, thanks for the recommended approach...

Meanwhile, I heard back from the dev of Profiles4Tasker ("Martin") -- he's still alive and involved, but no longer maintains his work on CM Profiles (the OS feature, not the same-named app!). He explained that Profiles4Tasker does indeed contain a "condition" which Tasker could read as a Boolean (e.g. "Is the active CM profile 'Night'?")...

...alas, this would mean:

1. Installing his app
2. Using it exclusively to select CM Profiles
3. Requiring Tasker to poll the app
4. Perform one or more Tasker Profiles to react

Sadly, that would kill the workflow I'm trying to preserve; namely, choosing CM Profiles directly through the OS's built-in Quick Panel, rather than using an shortcut or widget.

Sorry to sound so picky... what I'm after just may be more difficult than it's worth?!

At least Martin confirmed that I had already discovered... that Android annunciates that android.intent.action.profile_selected broadcast whenever a CM Profile gets activated!

One step forward, two steps back!!  (Should be the Tasker credo for n00bs)

 - Tim



--

Matt R

unread,
Jul 30, 2014, 2:34:23 PM7/30/14
to tas...@googlegroups.com
Did you try what I suggested to determine the variable name?

Matt

Tim G

unread,
Jul 31, 2014, 9:06:37 AM7/31/14
to tas...@googlegroups.com
Yes, but I must stress that doing so and reading the Log showed no signs of the android.intent.action.profile_selected intent ever being detected again.

Why it would be detected on Day One and never since has me flummoxed.


On Wed, Jul 30, 2014 at 1:34 PM, Matt R <matthew.r...@gmail.com> wrote:
Did you try what I suggested to determine the variable name?

Matt

--

Tim G

unread,
Jul 31, 2014, 9:47:23 AM7/31/14
to tas...@googlegroups.com
I finally had the time to compile my notes and share them properly with you below:

I see these entries in my system log (generated by the OS, not Tasker... because they never appear in Tasker's Debug log):

07-31 08:28:25.435   851   861 D ProfileService: Set active profile to: c0fcca6f-dc3a-4f65-a8c2-02d69b4969ea - Driving

and

#107: act=android.intent.action.PROFILE_SELECTED flg=0x10 (has extras)
    extras: Bundle[{lastName=Home, name=Driving, uuid=83517489-dba7-4063-8deb-102bcabb63a0}]
  

Tasker Profile & Task (never activated):

Profile: Detect Profile Change (13)
Event: Intent Received [ Action:android.intent.action.profile_selected Cat:None Cat:None Scheme:* Mime Type:* ]
Enter: Test (36)
A1: Flash [ Text:Yup Long:Off ]

Note that the name of the CM Profile I selected is "Driving".  I suppose I will have to make another Tasker profile (oh, how I wish these were called Triggers!) to try and catch an entirely different Intent just to prove my installation of Tasker is working in that regard.

Everything else I do in Tasker works marvelously and without this kind of hitch!

 - Tim



On Wed, Jul 30, 2014 at 1:34 PM, Matt R <matthew.r...@gmail.com> wrote:
Did you try what I suggested to determine the variable name?

Matt

--

Tim G

unread,
Jul 31, 2014, 10:07:26 AM7/31/14
to tas...@googlegroups.com
For grins and giggles, I set up a fresh Tasker Profile to catch the following Intent:

#5:
    BroadcastRecord{42540808 u-1 android.media.VOLUME_CHANGED_ACTION} to user -1
    Intent { act=android.media.VOLUME_CHANGED_ACTION flg=0x10 (has extras) }
      extras: Bundle[{android.media.EXTRA_VOLUME_STREAM_TYPE=2, android.media.EXTRA_VOLUME_STREAM_VALUE=5, android.media.EXTRA_PREV_VOLUME_STREAM_VALUE=5}]
 

Naturally, I entered android.media.volume_changed_action as the Intent action, and linked to the same Task ("Test") as above.

No dice. The Profile never becomes active, nor does the Flash appear, when I perform a simple Volume Up on my device. Shouldn't they, though?

If I've got this all wrong, please demote me to ultra-n00b status!

nanobrain

unread,
Jul 31, 2014, 11:02:39 AM7/31/14
to tas...@googlegroups.com
android.media.VOLUME_CHANGED_ACTION vs. android.media.volume_changed_action

Capitalization matters!!!

Matt R

unread,
Jul 31, 2014, 11:04:12 AM7/31/14
to tas...@googlegroups.com
I think you should have proper capitalization to match the OS log entry.  I see in your first post you said it had to be lowercase, but I think maybe that was a mistake.

Matt

Tim G

unread,
Jul 31, 2014, 1:09:47 PM7/31/14
to tas...@googlegroups.com
I should have specified that I tried both (thinking along the same lines), and neither version worked to trigger the Intent action.  (I understand that variable names must be all lower-case, per Tasker Wiki ... but that's a different discussion.)

nanobrain

unread,
Jul 31, 2014, 1:37:03 PM7/31/14
to tas...@googlegroups.com
I tried your volume example and it only worked for me using the capitalized version, therefore my note. Perhaps make sure that there are no trailing spaces in your Intent received profile context.

Tim G

unread,
Jul 31, 2014, 1:43:15 PM7/31/14
to tas...@googlegroups.com
I would've said the same thing, and not only double- and triple-checked to make sure of this (capitalization, no trailing spaces, etc.), I also Disabled and re-Enabled Tasker -- even rebooted my phone -- to no avail.

Having android.media.VOLUME_CHANGED_ACTION (and no leading or trailing whitespace) in the Profile's action field yielded no response at all when I changed Volume.

Time for me to re-install Tasker?  (If so, how do I preserve all the work I have saved!?)

Thanks guys. I feel like an idiot asking these basic questions...

 - Tim

Matt R

unread,
Jul 31, 2014, 1:44:48 PM7/31/14
to tas...@googlegroups.com
Maybe also make sure you're saving changes by fully exiting Tasker with the back button.  And make sure Tasker isn't disabled (greyed out Tasker icon in the main screen).

Matt

Tim G

unread,
Jul 31, 2014, 1:51:26 PM7/31/14
to tas...@googlegroups.com
Ah, I think it was your "exit with the back button" advice that finally made it work!

REALLY, TASKER? REALLY??  :-/

I feel so ashamed now. Will remember not to hit Home ever again when finished in Tasker.

Thanks again... argh

 - Tim



On Thu, Jul 31, 2014 at 12:44 PM, Matt R <matthew.r...@gmail.com> wrote:
Maybe also make sure you're saving changes by fully exiting Tasker with the back button.  And make sure Tasker isn't disabled (greyed out Tasker icon in the main screen).

Matt

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/VPTGbRz97fw/unsubscribe.

Matt R

unread,
Jul 31, 2014, 1:51:28 PM7/31/14
to tas...@googlegroups.com
Could something be stopping the broadcast?  Some broadcasts can be stopped I think if the broadcast receiver requests it, so it wouldn't reach all broadcast receivers.

Matt

Tim G

unread,
Jul 31, 2014, 3:13:21 PM7/31/14
to tas...@googlegroups.com

With your help I'm finally on my way.

On Jul 31, 2014 12:51 PM, "Matt R" <matthew.r...@gmail.com> wrote:
Could something be stopping the broadcast?  Some broadcasts can be stopped I think if the broadcast receiver requests it, so it wouldn't reach all broadcast receivers.

Matt

--
Reply all
Reply to author
Forward
0 new messages