Event OnClick for a button in a custom notification
- by Simone
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