【问题标题】:Tasker Plugin Variable Replacement: DeveloperTasker 插件变量替换:开发人员
【发布时间】:2016-08-21 07:53:24
【问题描述】:

我正在为 Taker Android 应用程序制作插件。该插件本质上将允许人们使用自己的设置值动态创建列表和卡片视图。

我认为允许使用 Tasker 变量来设置列表项等会很好。这就是我正在努力解决的问题。

这是我的代码部分(在我的 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);

这基本上是将我的值设置为一个包,然后根据我的理解,“setVriableReplaceKeys”函数会遍历我在包中指定的每个 keypai,以用当前值替换任何 taskerr 变量(例如 %BATT)存储在主机中。以下不起作用,我只看到写出的变量名没有任何值,所以如果我将 %BATT 用于测试它,我会在列表中看到 %BATT 而不是实际的电池百分比。

任何帮助将不胜感激。我已经玩了很久了。

【问题讨论】:

    标签: android automation tasker


    【解决方案1】:

    即使这已经有一段时间了,也许答案会像这个问题对我一样帮助其他人。

    1. 您的代码存在一些问题。一开始,setVariableReplaceKeys 需要一个 StringArray,所以这就足够了:

    if ( TaskerPlugin.Setting.hostSupportsOnFireVariableReplacement( this ) )
      TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle,
      new String [] { "MessageString","ContentString","TextColour","myArray" } );
    }
    
    1. if 语句中缺少花括号。
    2. 您调用了两次 putExtras。第一个电话就足够了。

    setVariableReplaceKeys 将为您的捆绑包添加另一个额外内容。如果您在某处检查捆绑包是否有效,请记住这一点。

    【讨论】:

    • 谢谢,我同意这仍然会帮助一些人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 2015-07-01
    相关资源
    最近更新 更多