我想从我从应用程序A =管理员发送到应用程序B =用户的通知开始未决意图。我想知道是否有可能在用户或管理员立即(从两端)收到通知的情况下打开未决Intent?
当我尝试打开从管理员发送到用户应用程序的通知时,我的应用程序崩溃,反之亦然,但是我在两个应用程序中都使用下面的相同方法。我在做什么错了?
注意:它只是一个聊天和建议应用程序,它的工作原理与任何其他聊天应用程序一样。
// sending notification to devices with versions below Oreo(android 8.0)
private void sendNotification(RemoteMessage remoteMessage) {
String user = remoteMessage.getData().get("user");
String icon = remoteMessage.getData().get("icon");
String title = remoteMessage.getData().get("title");
String body = remoteMessage.getData().get("body");
RemoteMessage.Notification notification = remoteMessage.getNotification();
// creating a pendingIntent for notification
int j = Integer.parseInt(user.replaceAll("[\\D]",""));
Intent intent = new Intent(this,MessageActivity.class);
Bundle bundle = new Bundle();
bundle.putString("userid",user);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,j,intent,PendingIntent.FLAG_ONE_SHOT);
// notification sound uri
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// creating an instance of Notification builder and setting its properties
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.app_logo_round)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(false)
.setSound(defaultSound)
.setVibrate(new long[]{1000,1000,1000})
.setWhen(System.currentTimeMillis());
.setContentIntent(pendingIntent);
// creating an instance of Notification Manager
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int i = 0;
if(j > 0){
i = j;
}
// starting the notification
nm.notify(i,builder.build());
}
我想要实现的是,如果管理员向用户发送一条消息,其中包含通知,反之亦然。