Event OnClick for a button in a custom notification

Posted by Simone on Stack Overflow See other posts from Stack Overflow or by Simone
Published on 2011-03-29T21:29:02Z Indexed on 2012/09/21 15:38 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

I have a custom notification with a button. To set the notification and use the event OnClick on my button I've used this code:

//Notification and intent of the notification 
Notification notification = new Notification(R.drawable.stat_notify_missed_call,
            "Custom Notification", System.currentTimeMillis());

Intent mainIntent = new Intent(getBaseContext(), NotificationActivity.class);
PendingIntent pendingMainIntent = PendingIntent.getActivity(getBaseContext(),
    0, mainIntent , 0);
notification.contentIntent = pendingMainIntent;

//Remoteview and intent for my button
RemoteViews notificationView = new RemoteViews(getBaseContext().getPackageName(),
    R.layout.remote_view_layout);

Intent activityIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:190"));
PendingIntent pendingLaunchIntent = PendingIntent.getActivity(getBaseContext(), 0,
            activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

notificationView.setOnClickPendingIntent(R.id.button1,
    pendingLaunchIntent);

notification.contentView = notificationView;

notificationManager.notify(CUSTOM_NOTIFICATION_ID, notification);

With this code I've a custom notification with my custom layout...but I can't click the button! every time I try to click the button I click the entire notification and so the script launch the "mainIntent" instead of "activityIntent".

I have read in internet that this code doesn't work on all terminals. I have tried it on the emulator and on an HTC Magic but I have always the same problem: I can't click the button!

My code is right? someone can help me?

Thanks,

Simone

© Stack Overflow or respective owner

Related posts about android

Related posts about button