2017-12-15 21 views
0

Firebase経由で通知を受け取ることができるAndroidアプリがあります。これらの通知は、Webサイト上のユーザーアクションによってトリガーされます。その後、APIはFirebaseに通知要求を送信します。Androidアプリは通知を受け取り続ける

最近、私のアプリはノンストップの通知を受け続けるという問題にぶつかってきました。これは直接通知とトピックメッセージの両方で起こっているようです。 最初はAPIが何らかのループで停止していると思っていましたが、Firebaseコンソールから直接送信する通知でこのようなことは起こりません。私自身の理論では、Firebaseは通知が宛先のデバイスに到着しなかったと考えて、それを再送信しています。

私のアプリのiOS版にはこの問題はないようです。

マイonMessageReceived()

@Override 
public void onMessageReceived(RemoteMessage message) { 
    Log.d(getClass().getName(), "Received notification"); 
    Map data = message.getData(); 
    try { 
     String scope = (String) data.get("scope"); 
     if(scope == null){ 
      Log.w(getClass().getName(), "Received notification with no scope"); 
      return; 
     } 

     String senderName = (String) data.get("senderName"); 
     String notificationMessage = (String) data.get("message"); 
     SharedPreferences notificationPreferences = getSharedPreferences(Constants.PREF_NOTIFICATION_SETTINGS, 0); 

     switch(scope){ 
      case Constants.NOTIFICATION_SCOPE_PROTOCOL: 
       handleProtocolUpdateMessage(data); 
       return; // PROTOCOL notifications are not stored in DB 
      case Constants.NOTIFICATION_SCOPE_USERSETTINGS: 
       handleUserSettingsUpdateMessage(data); 
       return; // USERSETTINGS notifications are not stored in DB 
      case Constants.NOTIFICATION_SCOPE_DEVICE: 
       if(notificationPreferences.getBoolean(Constants.PREF_DEVICE_NOTIFICATION_FILTER, true)){ 
        updateUnreadNotificationCounter(); 
        createNotification(scope, senderName, notificationMessage); 
       } 
       break; 
      case Constants.NOTIFICATION_SCOPE_INVENTORY: 
       if(notificationPreferences.getBoolean(Constants.PREF_INVENTORY_NOTIFICATION_FILTER, true)){ 
        updateUnreadNotificationCounter(); 
        createNotification(scope, senderName, notificationMessage); 
       } 
       break; 
      case Constants.NOTIFICATION_SCOPE_JOURNAL: 
       if(Application.test(this)){ 
        return; 
       }else{ 
        if(notificationPreferences.getBoolean(Constants.PREF_JOURNAL_NOTIFICATION_FILTER, true)){ 
         updateUnreadNotificationCounter(); 
         createNotification(scope, senderName, notificationMessage); 
        } 
       } 
       break; 
      case Constants.NOTIFICATION_SCOPE_SUPPLY: 
       if(notificationPreferences.getBoolean(Constants.PREF_SUPPLIES_NOTIFICATION_FILTER, true)){ 
        updateUnreadNotificationCounter(); 
        createNotification(scope, senderName, notificationMessage); 
       } 
       break; 
      case Constants.NOTIFICATION_SCOPE_SYSTEM: 
       if(notificationPreferences.getBoolean(Constants.PREF_SYSTEM_NOTIFICATION_FILTER, true)){ 
        updateUnreadNotificationCounter(); 
        if (Application.test(this)) { 
         createNotification(scope, "A", notificationMessage); 
        } else { 
         createNotification(scope, "B", notificationMessage); 
        } 
        break; 
       } 
       break; 
      default: 
       //If scope doesn't match any known scopes then return 
       return; 
     } 

     saveNotification(data); 
    }catch(ClassCastException e){ 
     Log.e(getClass().getName(), "Error while parsing notification contents", e); 
    } 
} 
+0

理解を深めるためにコードを投稿してください。 – Raj

+0

@Raj関連するコードを追加しました。 – Anubis

+0

ok createNotificationメソッドのコードも投稿してください。一意の通知IDがnotifyメソッドを渡したことを確認してください – Raj

答えて

1

私は、11.0.1からの最新バージョンにFirebaseを更新していない11.6.1と問題がもはや発生するようです。

関連する問題