使用 Android Studio 的 FCM 通知

问题描述:

我设法从 PHP 文件发送通知消息,并使用 Firebase Cloud Messaging (FCM) 发送到手机.

I managed to send notification message from PHP file and send to mobile phone using Firebase Cloud Messaging (FCM).

一旦用户点击移动托盘上的通知消息,我如何重定向到另一个具有相同消息加上时间和日期的布局?

Once the user click on the notification message on mobile tray, how can I redirect to another layout with same message plus time and date?

这是我在 FirebaseMessagingService.java 中的代码(使用 Android Studio)

Here is my code in FirebaseMessagingService.java (using Android Studio)

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    showNotification(remoteMessage.getData().get("message"));
}

private void showNotification(String message) {

    Intent i = new Intent(this,MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setAutoCancel(true)
            .setContentTitle("Notification")
            .setContentText(message)
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentIntent(pendingIntent)
            .setSound(defaultSoundUri);



    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    manager.notify(0,builder.build());
}

}

检查这个.

private void sendNotification(String messageBody)
{
 Intent intent = new Intent(this, MainActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("Firebase Push Notification")
        .setContentText(messageBody)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);

   NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

 notificationManager.notify(0, notificationBuilder.build());
}