androidautomationtasker

Tasker Plugin Variable Replacement: Developer


I'm making a plugin for the Taker Android app. The plugin will essentially allow people to create list and cardviews dynamically using their own set values.

I thought it'd be nice to also allow the use of Tasker variables to set thee list items etc. This is the it I'm struggling with.

This is the section of my code that I've got for this bit (In my EditActivity):

resultBundle.putString("MessageString", message);
            resultBundle.putString("ContentString", AlertContents);
            resultBundle.putString("BackgroundColour", BackgroundCol);
            resultBundle.putString("TextColour", TextCol);
            resultBundle.putStringArrayList("myArray", theList);
            resultIntent.putExtras(resultBundle);

            //Take above values and replace any %Variables with the Tassker values in the host

            if ( TaskerPlugin.Setting.hostSupportsOnFireVariableReplacement( this ) )
                TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "MessageString" } );
            TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "ContentString" } );
            TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "BackgroundColour" } );
            TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "TextColour" } );
            TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "myArray " } );

            resultIntent.putExtras(resultBundle);

Essetially what this does is set my values into a bundle, and then from my understanding the 'setVriableReplaceKeys' function goes through each keypai I specify in the bundle to replace any taskerr variables (%BATT, for example) with thee current values stored in the host. The below isn't working, I just see the variable names written out with no value, so if I put %BATT to test it, I see %BATT in the list rather than the actual battery percentage.

Any help would be greatly appreciated. I've been playing with it for ages.


Solution

  • Even if this has been while, maybe the answer will help others like the question did for me.

    1. There are some problems with your code. At first, setVariableReplaceKeys expects a StringArray, so this would be sufficient:

    if ( TaskerPlugin.Setting.hostSupportsOnFireVariableReplacement( this ) )
      TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle,
      new String [] { "MessageString","ContentString","TextColour","myArray" } );
    }
    
    1. Curly braces are missing in your if statement.
    2. You are calling putExtras twice. The first call would be enough.

    setVariableReplaceKeys will put another extra to your bundle. Keep that in mind if you're checking somewhere if the bundle is valid.