3

Firebase クラウド メッセージングを使用しているアプリを開発しています。そして、私はクリーンなアーキテクチャを使用しています。FirebaseMessaging クラスはデータ層にあります。そのクラスは次のようになります。

  @Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    if(remoteMessage.getMessageType()==null) {
        sendNotification(remoteMessage);

}

private void sendNotification(RemoteMessage remoteMessage) {
    NotificationCompat.Builder notification=new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.asp)
            .setContentText(remoteMessage.getNotification().getBody())
            .setContentTitle(remoteMessage.getNotification().getTitle())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification.build());

}

ご覧のとおり、関数 sendNotification は、メッセージがデバイスに届いたときに通知を作成するためのものです。そして、この関数をレイヤーを介してプレゼンテーション レイヤーにプッシュし、通知を行うためのすべてのロジックを実行する必要があります。しかし、関数 sendNotification はリモート メッセージである引数を持っており、ドメイン レイヤーは Google Play サービスをサポートしていないため、ドメイン レイヤーを介してリモート メッセージをプッシュできないため、その方法がわかりません。この関数 sendNotification をプレゼンテーション層にプッシュする方法を知っている人はいますか?

4

0 に答える 0