1

I want to get the values from extra key value which I am sending from urban air ship. Please help how to get those values. I am able to get the push notifications. But I don't know how to get the data from payload.

public class IntentReceiver extends BaseIntentReceiver {

    private static final String TAG = "IntentReceiver";
    private String video_id ="123456";

    @Override
    protected void onChannelRegistrationSucceeded(Context context, String channelId) {
        Log.i(TAG, "Channel registration updated. Channel Id:" + channelId + ".");

        // Broadcast that the channel updated. Used to refresh the channel ID on the main activity.
        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MainActivity.ACTION_UPDATE_CHANNEL));
    }

    @Override
    protected void onChannelRegistrationFailed(Context context) {
        Log.i(TAG, "Channel registration failed.");
    }
    @Override
    protected void onPushReceived(Context context, PushMessage message, int notificationId) {
        Log.i(TAG, "Received push notification. Alert: " + message.getTitle() + ". Notification ID: " + notificationId);


    @Override
    protected void onBackgroundPushReceived(Context context, PushMessage message) {
        Log.i(TAG, "Received background push message: " + message);
    }

    @Override
    protected boolean onNotificationOpened(Context context, PushMessage message, int notificationId) {
        Intent launch = new Intent(Intent.ACTION_MAIN);
        launch.setClass(UAirship.shared().getApplicationContext(),
                MainActivity.class);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launch.putExtra("NotificationMessage", "rich push notification recieved");
        context.startActivity(launch);
        /*//pending intent
        Intent notificationIntent = new Intent(context, MainActivity.class);
        Notification notification = new Notification();
        notificationIntent.putExtra("NotificationMessage", "rich push notification recieved");
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, "", "", pendingNotificationIntent);*/
        return false;
    }

    @Override
    protected boolean onNotificationActionOpened(Context context, PushMessage message, int notificationId, String buttonId, boolean isForeground) {
        Log.i(TAG, "User clicked notification button. Button ID: " + buttonId + " Alert: " + message.getAlert());
        return false;
    }


    @Override
    protected void onNotificationDismissed(Context context, PushMessage message, int notificationId) {
        Log.i(TAG, "Notification dismissed. Alert: " + message.getAlert() + ". Notification ID: " + notificationId);
    }
}

2 Answers2

0

To get the extra data use the getPushBundle on the message. So if I have something called "action" it would be this.

    Bundle pushBundle = message.getPushBundle();

    String action = null;
    if (pushBundle != null) {
        action = pushBundle.get("action").toString();
    }
Koppo
  • 591
  • 4
  • 15
0

You can get the bundle out of the PushMessage as rightly said by @Koppo Bundle pushBundle = message.getPushBundle();

and iterate the bundle and get all the extras in it. then you can decide which one to handle further for your application One more post available on this iteration logic. you can check this as well https://stackoverflow.com/a/16782044/4781403

Community
  • 1
  • 1
Santhana
  • 233
  • 1
  • 5