I'm using a Custom Push BroadCast Receiver as given here

I have fired an intent from the custom receiver to the activity with the custom data passed as shown in the snippet:

public class NotificationReceiver extends BroadcastReceiver

{ public void onReceive(Context context, Intent intent) { if (intent == null) return;

    //Let Pushwoosh SDK to pre-handling push (Pushwoosh track stats, opens rich pages, etc.).
    //It will return Bundle with a push notification data
    Bundle pushBundle = PushManagerImpl.preHandlePush(context, intent);
    if(pushBundle == null)
        return;

    //get push bundle as JSON object
    JSONObject dataObject = PushManagerImpl.bundleToJSON(pushBundle);
    Log.d("APIPushwoosh",dataObject.toString());
    //Get default launcher intent for clarity
    Intent launchIntent  = new Intent(context, Home2Activity.class);

    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    //Put push notifications payload in Intent
    launchIntent.putExtras(pushBundle);
    launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString());

    //Start activity!
    context.startActivity(launchIntent);

    //Let Pushwoosh SDK post-handle push (track stats, etc.)
    PushManagerImpl.postHandlePush(context, intent);
}

}

The intent to the activity I have fired as shown :

Intent launchIntent  = new Intent(context, Home2Activity.class);
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    //Put push notifications payload in Intent
    launchIntent.putExtras(pushBundle);
    launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString());
    //Start activity!
    context.startActivity(launchIntent);

The Home2Activity contains the code as follows :

registerReceivers();

    final PushManager pushManager = PushManager.getInstance(this);


    class RichPageListenerImpl implements PushManager.RichPageListener
    {
        @Override
        public void onRichPageAction(String actionParams)
        {
            Log.d("Pushwoosh", "Rich page action: " + actionParams);
        }

        @Override
        public void onRichPageClosed()
        {
            Log.d("Pushwoosh", "Rich page closed");
        }
    }

    pushManager.setRichPageListener(new RichPageListenerImpl());

    //pushManager.setNotificationFactory(new NotificationFactorySample());

    //Start push manager, this will count app open for Pushwoosh stats as well
    try
    {
        pushManager.onStartup(this);
    }
    catch (Exception e)
    {
        Log.e("Pushwoosh", e.getLocalizedMessage());
    }

    //Register for push!
    pushManager.registerForPushNotifications();

    //check launch notification (optional)
    String launchNotificatin = pushManager.getLaunchNotification();
    if (launchNotificatin != null)
    {
        Log.d("Pushwoosh", "Launch notification received: " + launchNotificatin);
    }
    else
    {
        Log.d("Pushwoosh", "No launch notification received");
    }

    // send local notification
    PushManager.scheduleLocalNotification(getApplicationContext(), "XYZ app launched first push test", 5);

//Registration receiver
BroadcastReceiver mBroadcastReceiver = new BaseRegistrationReceiver()
{
    @Override
    public void onRegisterActionReceive(Context context, Intent intent)
    {
        checkMessage(intent);
    }
};

//Push message receiver
private BroadcastReceiver mReceiver = new BasePushMessageReceiver()
{
    @Override
    protected void onMessageReceive(Intent intent)
    {
        //JSON_DATA_KEY contains JSON payload of push notification.
        doOnMessageReceive(intent.getExtras().getString(JSON_DATA_KEY));


    }
};

//Registration of the receivers
public void registerReceivers()
{
    IntentFilter intentFilter = new IntentFilter(getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");

    if (broadcastPush)
        registerReceiver(mReceiver, intentFilter, getPackageName() +".permission.C2D_MESSAGE", null);

    registerReceiver(mBroadcastReceiver, new IntentFilter(getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));
}

public void unregisterReceivers()
{
    //Unregister receivers on pause
    try
    {
        unregisterReceiver(mReceiver);
    }
    catch (Exception e)
    {
        // pass.
    }

    try
    {
        unregisterReceiver(mBroadcastReceiver);
    }
    catch (Exception e)
    {
        //pass through
    }
}

@Override
public void onResume()
{
    super.onResume();

    //Re-register receivers on resume
    registerReceivers();
}

@Override
public void onPause()
{
    super.onPause();

    //Unregister receivers on pause
    unregisterReceivers();
}

private void checkMessage(Intent intent)
{
    if (null != intent)
    {
        if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
        {
            doOnMessageReceive(intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT));
        }
        else if (intent.hasExtra(PushManager.REGISTER_EVENT))
        {
            doOnRegistered(intent.getExtras().getString(PushManager.REGISTER_EVENT));
        }
        else if (intent.hasExtra(PushManager.UNREGISTER_EVENT))
        {
            doOnUnregistered(intent.getExtras().getString(PushManager.UNREGISTER_EVENT));
        }
        else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
        {
            doOnRegisteredError(intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT));
        }
        else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
        {
            doOnUnregisteredError(intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT));
        }

        resetIntentValues();
    }
}

public void doOnRegistered(String registrationId)
{
    Log.d("Pushwoosh","doOnRegistered "+registrationId);
}

public void doOnRegisteredError(String errorId)
{
    Log.d("Pushwoosh","doOnRegisteredError "+errorId);
}

public void doOnUnregistered(String registrationId)
{
    Log.d("Pushwoosh","doOnUnregistered "+registrationId);
}

public void doOnUnregisteredError(String errorId)
{
    Log.d("Pushwoosh","doOnUnregisteredError "+errorId);
}

public void doOnMessageReceive(String message)
{
    // Parse custom JSON data string.
    // You can set background color with custom JSON data in the following format: { "r" : "10", "g" : "200", "b" : "100" }
    // Or open specific screen of the app with custom page ID (set ID in the { "id" : "2" } format)
    try
    {
        JSONObject messageJson = new JSONObject(message);

        JSONObject customJson = new JSONObject(messageJson.getString("u"));

        test.setText(customJson.getString("type"));


    }
    catch (JSONException e)
    {
        // No custom JSON. Pass this exception
    }
}

private void resetIntentValues()
{
    Intent mainAppIntent = getIntent();

    if (mainAppIntent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
    {
        mainAppIntent.removeExtra(PushManager.PUSH_RECEIVE_EVENT);
    }
    else if (mainAppIntent.hasExtra(PushManager.REGISTER_EVENT))
    {
        mainAppIntent.removeExtra(PushManager.REGISTER_EVENT);
    }
    else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_EVENT))
    {
        mainAppIntent.removeExtra(PushManager.UNREGISTER_EVENT);
    }
    else if (mainAppIntent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
    {
        mainAppIntent.removeExtra(PushManager.REGISTER_ERROR_EVENT);
    }
    else if (mainAppIntent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
    {
        mainAppIntent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT);
    }

    setIntent(mainAppIntent);
}

My problem is the custom data is not being displayed in the textview of the activity. It's being displayed correctly in the log of the NotificationReceiver File though as :

{"title":"hiiii","vib":"1","pri":"","u":"{\"type\":\"incomingRequest\",\"request_id\":\"anupam-test-1234\"}","userdata":{"type":"incomingRequest","request_id":"anupam-test-1234"},"collapse_key":"do_not_colla
asked 04 Feb '16, 19:59
Anupam%20Chugh's gravatar image

Anupam Chugh
14

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×447
×326
×25

question asked: 04 Feb '16, 19:59

question was seen: 1,313 times

last updated: 04 Feb '16, 19:59