3

I get notification in my application through BroadcastReceiver, The question is , How can I parse data to an activity and make a dialog with the received data ?

this is my code but when I click on the notification , nothing happens :

NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse(link));
        PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);

        Notification myNotification = new NotificationCompat.Builder(ctx)
                .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false).setLargeIcon(remote_picture)
                .setContentTitle(onvan).setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg).setContentIntent(pending).build();
        notificationManager.notify(1, myNotification);

I've some variablese like link , msg, onvan that contains my data and I need to send these variables to an activity and make a dialog .

How can I do so ?

Harshad
  • 1,344
  • 1
  • 10
  • 25
donald draper
  • 561
  • 2
  • 9
  • 24

2 Answers2

1

Try this:

Intent notifyIntent = new Intent(context,YourActivityClassHere.class);
notifyIntent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
//UNIQUE_ID if you expect more than one notification to appear
PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, UNIQUE_ID, 
            notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

just make the PendingIntent open up one of your Activities and have your Activity be complete transparent and just open a Dialog.

EDIT: IF you want to open an Activity from notification click event:

Assuming that notif is your Notification object:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
notif.contentIntent = contentIntent;

For more detail visit here. Android - Prompt Dialog window when touch on Notification

Community
  • 1
  • 1
Harshad
  • 1,344
  • 1
  • 10
  • 25
1

You can send data from your notification to another Activity using method putExtra and put this

PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT));

inplace of this

PendingIntent pending = PendingIntent.getActivity(ctx, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);`
nick
  • 197
  • 1
  • 2
  • 16
inkedTechie
  • 684
  • 5
  • 13