mercredi 27 mai 2015

Android sending extra's with pending Intent

For my push notifications, I am sending some data which I will then choose which fragment I want to open. I am trying to do this by adding an Intent Extra to the Pending Intent but whenever I try to use this extra in the next Activity, it returns NULL.

I have read here I need to change the PendingActivity flag, but I have changed it a few times and made no difference. I must be making a silly mistake somewhere.

    private void sendNotification(String title, String msg, String fragment) {
    mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo_m_white)
//          .setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.icon_filled_m)).getBitmap())
            .setContentTitle(title)
            .setContentText(msg)
            .setSound(Uri.EMPTY)
            .setPriority(1)
            .setLights(Color.RED, 300, 5000)
            .setAutoCancel(true);
    Intent intent = new Intent(this, LoginActivity.class);
    intent.putExtra("fragment", fragment);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
    mBuilder.setContentIntent(pi);
    mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
}

Aucun commentaire:

Enregistrer un commentaire