问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/28658402/cannot-resolve-pendingintent-getactivity