PendingIntent sent from a notication.

Posted by totem on Stack Overflow See other posts from Stack Overflow or by totem
Published on 2010-06-13T13:53:27Z Indexed on 2010/06/13 15:52 UTC
Read the original article Hit count: 266

Filed under:
|
|

Hi, What im trying to accomplish is to send a notification through the notification manager that once clicked will do something in the application only if its currently running. i have tried to use:

notification.contentIntent = PendingIntent.getActivity(this, nNotificationCounter, Someintent, PendingIntent.FLAG_NO_CREATE)

Which allways caused an exception once trying to use the notify. I switched to:

Notification notification = new Notification(icon, tickerText, when);

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.some_notification);
contentView.setTextViewText(R.id.title, sTitle);
contentView.setTextViewText(R.id.text, sText);
notification.contentView = contentView;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.number = nNotificationCounter;

Intent notificationIntent = new Intent(this, MainWindow.class).setAction(ACTION_RESET_MESSGE_COUNTER);
notification.contentIntent = PendingIntent.getBroadcast(this, nNotificationCounter, notificationIntent, 0);

and although this code doesn't cause an exception. it doesnt call my BroadcastReceiver which is defined as follows:

public class IncomingReceiver extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(ACTION_RESET_MESSGE_COUNTER)) {
                    System.out.println("GOT THE INTENT");
                    return;
                }

            }
        }

and set in the onCreate:

IntentFilter filter = new IntentFilter(ACTION_RESET_MESSGE_COUNTER);
        IncomingReceiver receiver = new IncomingReceiver();
        context.registerReceiver(receiver, filter);

Does anyone see something wrong with the code? Or how would i go about to get messages when the notification is clicked, but not create any activity if it isn't already created.

edit: added the intent creation and notification creation.

Thanks, Tom

© Stack Overflow or respective owner

Related posts about android

Related posts about notifications