首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tasker Action插件变量替换

Tasker Action插件变量替换
EN

Stack Overflow用户
提问于 2017-11-06 03:13:36
回答 1查看 287关注 0票数 0

在这方面有很多问题,但我找不到一个适合我的情况的例子。我正在尝试将Tasker插件添加到我的应用程序中。它可以工作,但不会传递变量值。相反,仅传递变量名,如%BATT。

我在这里阅读:http://tasker.dinglisch.net/plugins.html

它说我必须在我的EditActivity中添加以下几行:

代码语言:javascript
复制
  if ( TaskerPlugin.Setting.hostSupportsOnFireVariableReplacement( this ) )
                TaskerPlugin.Setting.setVariableReplaceKeys( resultBundle, new String [] { "com.saple.plugin.MYVALUE" } );

但我找不到把这些线放在哪里。下面是我的editactivity类:

代码语言:javascript
复制
package com.test.app;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

import com.aktuna.gear.defilmirz.R;
import com.aktuna.gear.defilmirz.bundle.BundleScrubber;
import com.aktuna.gear.defilmirz.bundle.PluginBundleManager;

//import com.twofortyfouram.locale.Intent;

/**
 * This is the "Edit" activity for a Locale Plug-in.
 * <p>
 * This Activity can be started in one of two states:
 * <ul>
 * <li>New plug-in instance: The Activity's Intent will not contain
 * {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE}.</li>
 * <li>Old plug-in instance: The Activity's Intent will contain
 * {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} from a previously saved plug-in instance that the
 * user is editing.</li>
 * </ul>
 *
 * @see com.twofortyfouram.locale.Intent#ACTION_EDIT_SETTING
 * @see com.twofortyfouram.locale.Intent#EXTRA_BUNDLE
 */
public final class EditActivity extends AbstractPluginActivity
{

    @Override
    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        BundleScrubber.scrub(getIntent());

        final Bundle localeBundle = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
        BundleScrubber.scrub(localeBundle);

        setContentView(R.layout.main);

        if (null == savedInstanceState)
        {
            if (PluginBundleManager.isBundleValid(localeBundle))
            {
                final String message =
                        localeBundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
                ((EditText) findViewById(android.R.id.text1)).setText(message);
            }
        }
    }

    @Override
    public void finish()
    {
        if (!isCanceled())
        {
            final String message = ((EditText) findViewById(android.R.id.text1)).getText().toString();

            if (message.length() > 0)
            {
                final Intent resultIntent = new Intent();

                /*
                 * This extra is the data to ourselves: either for the Activity or the BroadcastReceiver. Note
                 * that anything placed in this Bundle must be available to Locale's class loader. So storing
                 * String, int, and other standard objects will work just fine. Parcelable objects are not
                 * acceptable, unless they also implement Serializable. Serializable objects must be standard
                 * Android platform objects (A Serializable class private to this plug-in's APK cannot be
                 * stored in the Bundle, as Locale's classloader will not recognize it).
                 */
                final Bundle resultBundle =
                        PluginBundleManager.generateBundle(getApplicationContext(), message);
              resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE, resultBundle);

                /*
                 * The blurb is concise status text to be displayed in the host's UI.
                 */
                final String blurb = generateBlurb(getApplicationContext(), message);
                resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB, blurb);

                setResult(RESULT_OK, resultIntent);
            }
        }

        super.finish();
    }

    /**
     * @param context Application context.
     * @param message The toast message to be displayed by the plug-in. Cannot be null.
     * @return A blurb for the plug-in.
     */
    /* package */static String generateBlurb(final Context context, final String message)
    {
        final int maxBlurbLength =
                context.getResources().getInteger(R.integer.twofortyfouram_locale_maximum_blurb_length);

        if (message.length() > maxBlurbLength)
        {
            return message.substring(0, maxBlurbLength);
        }

        return message;
    }
}

如果有人能告诉我该怎么做我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-11-06 03:34:46

我找到了。generateBundle函数在PluginBundleManager.generateBundle下,我所要做的就是添加: result.putString("net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS",BUNDLE_EXTRA_STRING_MESSAGE);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47125543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档