String extra passed to query receiver is null

291 views
Skip to first unread message

taryn.c...@gmail.com

unread,
Oct 27, 2015, 10:48:22 AM10/27/15
to Tasker - Developers
I am trying to write an event plugin for Tasker. I am having trouble getting a string extra I am adding to ACTION_REQUEST_QUERY and then sending as a broadcast to then be used in Query Receiver to test against PluginBundleManager.BUNDLE_EXTRA_STRING. The event shows up as a selectable option in Tasker so my EditActivity works fine, but I cannot get the paired Tasks to be initiated.  Logcat shows me that the problem is that pageIdPressed is null ( eventButtonPressed  has the string value it is supposed to) when I ask for SystemOut under QueryReceiver but it has a string value I can see using Display exception in the Main Activity. So the value of this string is getting lost or not being sent right in my broadcast.  I have searched for and found similar Broadcast/Intentextra issues on StackOverflow, but the solutions I have seen involve using getParent() in the receiver and android studio flags getParent() as unable to resolve method if I try to use it in query receiver.
This is the relevant code in Main activity where I broadcast the intent (it is nested in a Broadcast Receiver because I want it done in response to receiving an intent):
 
 
private BroadcastReceiver messageReceiver = new BroadcastReceiver() {
    @Override
public void onReceive(Context context, Intent intent) {
        if (intent.getAction() == TileEvent.ACTION_TILE_OPENED) {
            TileEvent tileOpenData = intent.getParcelableExtra(TileEvent.TILE_EVENT_DATA);
        } else if (intent.getAction() == TileEvent.ACTION_TILE_BUTTON_PRESSED) {
TileButtonEvent buttonData = intent.getParcelableExtra(TileEvent.TILE_EVENT_DATA);
            UUID pageButtonPressed = buttonData.getPageID();
            String pageIdPressed = pageButtonPressed.toString();
            displayExceptionMessage("Button event received\n" + pageButtonPressed.toString());
Intent INTENT_REQUEST_REQUERY = new Intent(com.twofortyfouram.locale.Intent.ACTION_REQUEST_QUERY);
INTENT_REQUEST_REQUERY.putExtra("PAGE_ID", pageIdPressed);
            INTENT_REQUEST_REQUERY.putExtra(com.twofortyfouram.locale.Intent.EXTRA_ACTIVITY,
                    EditActivity.class.getName());
            TaskerPlugin.Event.addPassThroughMessageID(INTENT_REQUEST_REQUERY);
            sendBroadcast(INTENT_REQUEST_REQUERY);
        } else if (intent.getAction() == TileEvent.ACTION_TILE_CLOSED) {
            TileEvent tileCloseData = intent.getParcelableExtra(TileEvent.TILE_EVENT_DATA);
        }
    }
};
 
Here is my QueryReceiver:
 
public final class QueryReceiver extends BroadcastReceiver
{ int messageID;
 
    //**
// * @param context {@inheritDoc}.
//* @param intent the incoming {@link com.twofortyfouram.locale.Intent#ACTION_QUERY_CONDITION} Intent. This
//* should always contain the {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} that was
//* saved by {@link EditActivity} and later broadcast by Locale.
//*/
@Override
public void onReceive(final Context context, final Intent intent)
{
/*
* Always be strict on input parameters! A malicious third-party app could send a malformed Intent.
*/
 
if (!com.twofortyfouram.locale.Intent.ACTION_QUERY_CONDITION.equals(intent.getAction()))
        {
            if (Constants.IS_LOGGABLE)
            {
                Log.e(Constants.LOG_TAG,
                      String.format(Locale.US, "Received unexpected Intent action %s", intent.getAction())); //$NON-NLS-1$
}
            return;
        }
 
        BundleScrubber.scrub(intent);
        final String pageButtonPressed = intent.getStringExtra("PAGE_ID");
final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
BundleScrubber.scrub(bundle);
 
if (PluginBundleManager.isBundleValid(bundle))
        {
            final String eventButtonPressed = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING);
 
System.out.println("eventButtonPressed is" + eventButtonPressed);
System.out.println("pageButtonPressed is" + pageButtonPressed);
 
if ( messageID == -1 )
setResultCode( com.twofortyfouram.locale.Intent.RESULT_CONDITION_UNKNOWN );
else
{
if (pageButtonPressed != null && eventButtonPressed == pageButtonPressed)
{
setResultCode(com.twofortyfouram.locale.Intent.RESULT_CONDITION_SATISFIED);
}
else
{
setResultCode(com.twofortyfouram.locale.Intent.RESULT_CONDITION_UNSATISFIED);
}
}
 
 
// * Because conditions are queried in the background and possibly while the phone is asleep, it is
// * necessary to acquire a WakeLock in order to guarantee that the service is started.
//*/
ServiceWakeLockManager.aquireLock(context);

 
Thanks for any assistance!
Taryn

 
 

 
 
 

Pent

unread,
Oct 29, 2015, 6:27:05 AM10/29/15
to Tasker - Developers, taryn.c...@gmail.com
Use TaskerPlugin.Event.addPassThroughData to pass event data through and
TaskerPlugin.Event.retrievePassThroughData to get it back.

Pent
Reply all
Reply to author
Forward
0 new messages