我的要求是,在tablayout片段内-> recyclerview->包含2个按钮(批准/拒绝),如果管理员单击了批准,则必须发送该特定用户的通知,请对此提供帮助。 ...
public void displayNotification(活动活动){
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationManager mNotificationManager =
(NotificationManager) activity.getSystemService(activity.NOTIFICATION_SERVICE);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(CHANNNEL_ID, CHANNEL_NAME, importance);
mChannel.setDescription(CHANNEL_DESC);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mNotificationManager.createNotificationChannel(mChannel);
}
PendingIntent helpPendingIntent = PendingIntent.getBroadcast(
activity,
REQUEST_CODE_HELP,
new Intent(activity, NotificationReceiver.class)
.putExtra(KEY_INTENT_HELP, REQUEST_CODE_HELP),
PendingIntent.FLAG_UPDATE_CURRENT
);
RemoteInput remoteInput = new RemoteInput.Builder(NOTIFICATION_REPLY)
.build();
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(android.R.drawable.ic_delete,
"Check Now...", helpPendingIntent)
.addRemoteInput(remoteInput)
.build();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity, CHANNNEL_ID)
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setContentTitle("Demo app")
.setContentText("approved clicked")
.setAutoCancel(true)
.setContentIntent(helpPendingIntent)
.addAction(action)
.addAction(android.R.drawable.ic_menu_directions, "cancel", helpPendingIntent);
NotificationManager notificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
这是我的代码,它在片段中可以很好地工作,但是在回收器视图中,它显示了空指针异常,而且我认为getActivity()在回收器视图适配器中也不起作用。
请提出任何建议...