本文介绍了无法解析PendingIntent.getActivity()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试发出自定义通知,但无法解决.
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());
}
这里的问题是,"getActivity"显示为错误(红色),它表示无法解析该符号(将鼠标悬停在该符号上). 谢谢.
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:我使用的是Android Studio.
PS: I use Android Studio.
推荐答案
替换
notification.setContentIntent( new PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));
使用
notification.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));
getActivity()
是类PendingIntent
的static
方法,并且不需要PendingIntent
实例即可被调用.
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.
这篇关于无法解析PendingIntent.getActivity()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!