2016-10-23 8 views
0

Firebase Cloud Messagingでプッシュ通知をスタックしようとしていますが、問題が発生しました。プッシュ通知がクリアされたことを検出する方法がわかりませんすべてのボタンをクリア)。Androidのクリア通知が検出されない

私はStackoverflowで見たほとんどすべてのチュートリアルをうまくいっていないので、何か不足しています。これは私の通知放送受信機である

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

final static String GROUP_KEY_EMAILS = "group_key_emails"; 

protected PendingIntent getContentIntent(String data) 
{ 
    Intent notificationIntent = new Intent(getApplicationContext(), SplashScreen.class); 
    notificationIntent.putExtra("custom", data); 
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    return PendingIntent.getActivity(getApplicationContext(), 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
} 

protected PendingIntent getDeleteIntent() 
{ 
    Intent intent = new Intent(getApplicationContext(), NotificationBroadcastReceiver.class); 
    intent.setAction("notification_cancelled"); 
    return PendingIntent.getBroadcast(getApplicationContext(), 1, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
} 

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 

    if(remoteMessage.getNotification() != null) 
    { 
     try { 
      Map<String, String> data = remoteMessage.getData(); 
      String customData = data.get("custom"); 
      JSONObject customJSON = new JSONObject(customData); 
      final JSONObject pushData = customJSON.getJSONObject("custom data"); 

      String message = remoteMessage.getNotification().getBody(); 
      Notification notif1 = new android.support.v4.app.NotificationCompat.Builder(getApplicationContext()) 
        .setContentTitle("My app") 
        .setContentText(message) 
        .setSmallIcon(R.drawable.icon) 
        .setAutoCancel(true) 
        .setGroup(GROUP_KEY_EMAILS) 
        .setContentIntent(getContentIntent(customData)) 
        .setDeleteIntent(getDeleteIntent()) 
        .build(); 

      NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); 
      notificationManager.notify(1, notif1); 
      AuxiliaryFunctions.addPushNotificationsMessage(getApplicationContext(), message); 
      int notifId = AuxiliaryFunctions.readPushNotificationsMessagesNum(getApplicationContext()); 
      if(notifId > 1) 
      { 
       NotificationCompat.InboxStyle style = new android.support.v4.app.NotificationCompat.InboxStyle() 
         .setSummaryText(notifId + " new messages"); 
       JSONArray messages = AuxiliaryFunctions.readPushNotificationsMessages(getApplicationContext()); 
       for(int i = 0; i < messages.length(); i++) 
       { 
        String localmessage = messages.getString(i); 
        style.addLine(localmessage); 
       } 
       Notification summaryNotification = new android.support.v4.app.NotificationCompat.Builder(getApplicationContext()) 
         .setContentTitle("My app "+notifId+" new messages") 
         .setSmallIcon(R.drawable.iconplus) 
         .setStyle(style) 
         .setGroup(GROUP_KEY_EMAILS) 
         .setGroupSummary(true) 
         .setAutoCancel(true) 
         .setContentIntent(getContentIntent("")) 
         .setDeleteIntent(getDeleteIntent()) 
         .build(); 

       notificationManager.notify(1, summaryNotification); 
      } 

     } catch (JSONException e) { 

     } 
    } 
    } 
} 

この

は私が今持っているものである

public class NotificationBroadcastReceiver extends BroadcastReceiver 
{ 

    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
    Log.e("", "NotificationBroadcastReceiver:onReceive"); 
    } 
} 

そして最後に、私は私のマニフェストにこのことを宣言する:まあ

 <receiver android:name="auxiliary.NotificationBroadcastReceiver"> 
     <intent-filter> 
      <action android:name="notification_cancelled"/> 
     </intent-filter> 
    </receiver> 

通知が正しく表示され、複数の通知があった場合にそれらが積み重なっていて、 rの通知のクリック(要約かどうか)はうまくいっており、通知は問題なく処理されます。 しかし、ユーザーが通知(要約または非表示)でスイープを作成するか、[すべての通知をクリア]ボタンをクリックすると、通知は消えますが、NotificationBroadcastReceiverは決して呼び出されません(ログNotificationBroadcastReceiver:onReceiveはコンソールに表示されません)。

私は何が欠けていますか?

答えて

0

私は非常に恥ずかしいです!私は私の問題の理由を見つけ出し、それは完全な愚かさでした。私は補助の前にドットを忘れてしまった

<receiver android:name="auxiliary.NotificationBroadcastReceiver"> 
     <intent-filter> 
      <action android:name="notification_cancelled"/> 
     </intent-filter> 
    </receiver> 

:私のAndroidManifestで

は、私はこれを持っていました。一度私はそれを置く:

<receiver android:name=".auxiliary.NotificationBroadcastReceiver"> 
      <intent-filter> 
       <action android:name="notification_cancelled"/> 
      </intent-filter> 
     </receiver> 

受信者のコールバックが呼び出されました。

私はAndroidManifestが間違った経路を解決するエラーを出さなかったことは驚きです。

関連する問題