Я использую службу сообщений Firebase, чтобы получать уведомления для моего приложения для Android, но эта служба не вызывается, но один раз! как справиться с этим, чтобы он вызывался всякий раз, когда я получал сообщение?
вот мой код:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String user_id = "0";
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
user_id = remoteMessage.getData().get("from_user");
}
String click_action = remoteMessage.getNotification().getClickAction();
Log.d(TAG, "Message data payload: " + click_action);
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle(), user_id, click_action);
}
private void sendNotification(String messageBody, String messageTitle, String user_id, String click_action) {
Intent intent = new Intent(click_action);
intent.putExtra("user_id", user_id);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
и есть моя полезная нагрузка:
const payload = {
notification: {
title: "New Friend Request",
body: `${userName} has sent you a Friend Request`,
icon: "default",
click_action: "com.example.alaa.lapitchatapp.Target_Notification"
},
data:{
from_user: from_user_id
}
};
Это услуга на Mainfest:
<service android:name=".FirebaseMessagingService">
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
</intent-filter>
</service>