I am trying to make a custom notification and cannot resolve this.
public void remNotifyClicked (View view){
notification.setSmallIcon(R.drawable.ic_launcher);
notification.setTicker("Ticker");
notification.setContentTitle("Notification");
notification.setContentText("Congratulation!");
notification.setWhen(System.currentTimeMillis());
Intent i = new Intent(this, SecondActivity.class);
notification.setContentIntent( new PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueId, notification.build());
}
The problem here is, "getActivity" is showing as error(red colored) and it says it cannot resolve the symbol(when hovered over it). Thanks.
PS: I use Android Studio.
A PendingIntent object wraps the functionality of an Intent object while allowing your app to specify something that another app should do, on your app's behalf, in response to a future action. For example, the wrapped intent might be invoked when an alarm goes off, or when the user taps on a notification.
Setting PendingIntent. FLAG_UPDATE_CURRENT : Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.
Replace
notification.setContentIntent( new PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));
with
notification.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));
getActivity()
is a static
method of the class PendingIntent
and does not require an instance of PendingIntent
in order to be invoked.
Try this. This will work.
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