2016-09-22 18 views
0

が、私は私のAndroidアプリNotificationComapt.Builderの中へアンドロイドFirebase通知プッシュ通知getSubText

public class NotificationMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     String title = remoteMessage.getNotification().getTitle(); 
     String message = remoteMessage.getNotification().getBody(); 

     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); 

     NotificationCompat.Builder nb = new NotificationCompat.Builder(this); 
     nb.setContentTitle(title); 
     nb.setContentText(message); 
     nb.setSmallIcon(R.drawable.iconanotifica); 
     nb.setAutoCancel(true); 
     nb.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); 
     nb.setLights(Color.BLUE, 3000, 3000); 

     nb.setContentIntent(pendingIntent); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, nb.build()); 
    } 
} 

に通知を管理するには、このクラスを使用して、と呼ばれる方法があります。 「remoteMessage.getNotification()。getSubText()」を取得するにはどうすればよいですか?

答えて

0

NotificationCompat.Builder.setSubText()は、通知テンプレートにテキストを追加します(Android NotificationCompat reference documentation)。デバイスが大判通知をサポートできない場合、これは効果がありません。

remoteMessage.getNotification()は、Firebase NotificationコンソールまたはFirebase Cloud Messaging実装のアプリケーションサーバーから送信したメッセージのnotification payloadを取得します。

あなたの通知メッセージに追加のデータ・パラメータを追加したい場合は、以下のオプションを使用してそれを行うことができます。Firebase通知コンソールで

  1. にカスタムデータのキーと値のペアを追加詳細オプションセクション。
  2. Firebase Cloud Messaging(FCM)を使用している場合は、messages with both notification and data payloadを送信できます。

使用remoteMessage.getData()その後、あなたの通知にサブテキストとして、それを使用し、特定の値を取得するために、クライアントアプリケーションとget()方法でメッセージのデータペイロードを取得します。

希望すると便利です。

+0

はい、動作します。しかし、私はアンドロイドアプリを使用して通知を送信し、これはPHPファイルによって管理されています。私がデータベースからnotifcationを送信した場合にのみ、サブテキストが表示されますが、アプリケーションから送信した場合は表示されません。手伝ってくれますか? – Simone

+0

こんにちは@Simone、もっと問題を広げてください。それが元のものと別の場合は、あなたの質問を更新するか、私の答えを受け入れて新しいスレッドを作成してください。 – weneedweeds

+0

いいえ、それは私が従いたい解決策ではありません。私はアンドロイドアプリからこの通知を送信し、サブテキストを設定する必要があります – Simone

関連する問題