1

通知を送信するためにFirebaseを使用するアプリケーションがあります。 Iそれらを送信し、通知が現れた場合、スタイルが提供されていますが、私はそれが意図しない]をクリックし、代わりの私にそれをやったときに通知の残りは、また通知の意図が私のURLに従わない

Notification notification = new NotificationCompat.Builder(getApplicationContext()) 
      .setSmallIcon(R.drawable.lascanadaslogo) 
      .setContentTitle("Titulo") 
      .setContentIntent(pi) 
      .setAutoCancel(true) 
      .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody())) 
      .build(); 

が記述されていないようそれは私のアプリ(メインページ)にそれを行います。私はあなたの全体のコードを示しています。

public class MyFirebaseMessagingService extends FirebaseMessagingService{ 

    private static final String TAG = "FCM Service"; 

    /** 
    * Called when message is received. 
    * 
    * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. 
    */ 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.lascanadas.es/reservas")); 
     PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); 
     Notification notification = new NotificationCompat.Builder(getApplicationContext()) 
       .setSmallIcon(R.drawable.lascanadaslogo) 
       .setContentTitle("Titulo") 
       .setContentIntent(pi) 
       .setAutoCancel(true) 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody())) 
       .build(); 

     NotificationManager notificationManager2 = (NotificationManager) getApplicationContext().getSystemService(Service.NOTIFICATION_SERVICE); 
     notificationManager2.notify(0, notification); 

     //Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
    } 
} 

答えて

0

Firebase Console for Notificationを使用している場合は、ユーザーがあなたのアプリを使用していない(アプリケーションはバックグラウンドで)場合、通知を制御できません。すべてFirebase SDKによって行われ、通知をクリックするとLauncher ActivityMainActivity)。しかし、あなたのユーザーが(フォアグラウンドで)あなたのアプリケーションを使用している場合は、あなたのonMessageReceived()メソッドが呼び出され、あなたのロジックが動作します。しかし、あなたのユーザーがあなたのアプリを使用していないときはいつも起こるので、おそらくサーバーを使ってデータメッセージを使用するようアドバイスします。サーバーではさらに簡単です。そこからあなたのonMessageReceivedが常に呼び出され、データを取得することができます。

Map<String,String> your_data = remoteMessage.getData; 
+0

ありがとうございました!私はサーバーとしてラズベリーを持っています。私はそれに使用しなければならないプログラムはどれですか? –

+0

@Jorge。私は確かにそのための簡単な選択肢があることを知っています。私はあなたにそれを手伝ってくれるでしょう。 'johnnnoni @ gmail.com'。長い議論はコメントではお勧めしません。私のメールを使ってください。 – Xenolion

0

それがバックグラウンドで動作している間、通知メッセージがアプリに送信されると、onMessageReceived()が起動されていないが、通知はSDKによって生成されます。これはthe documentationで説明されています。あなたのアプリがバックグラウンドにあるとき

通知メッセージが配信します。 この場合、通知はデバイスのシステムトレイに配信されます。 通知のユーザータップは、デフォルトでアプリランチャーを開きます。

あなたは通知の生成を制御できるようにonMessageReceived()が常に呼び出されるしたい場合は、data message instead of a notification messageを送信する必要があります。

関連する問題