无法解析 PendingIntent.getActivity()
Cannot resolve PendingIntent.getActivity()
我正在尝试制作自定义通知,但无法解决此问题。
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" 显示为错误(红色),它表示无法解析符号(将鼠标悬停在符号上时)。
谢谢
PS:我使用 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()
是 class PendingIntent
的 static
方法,不需要 PendingIntent
的实例即可调用。
试试这个。这会起作用。
我正在尝试制作自定义通知,但无法解决此问题。
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" 显示为错误(红色),它表示无法解析符号(将鼠标悬停在符号上时)。 谢谢
PS:我使用 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()
是 class PendingIntent
的 static
方法,不需要 PendingIntent
的实例即可调用。
试试这个。这会起作用。