This is my code, I want to open a URL when user clicks on notification.
This is the code:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));
Notification myNotification = new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(false)
.setLargeIcon(remote_picture)
.setContentTitle(onvan)
.setContentIntent(notificationIntent)
.setContentText(msg)
.setStyle(notiStyle)
.build();
notificationManager.notify(1, myNotification);
I got this error :
The method setContentIntent(PendingIntent) in the type NotificationCompat.Builder is not applicable for the arguments (Intent)
What am I doing wrong? How can I tell it to open browser when user clicks on the notification?
You have to add pending intent to the the notification.
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(link));
PendingIntent pending = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.setContentIntent(pending);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With