2017-11-26 6 views
0

특정 fcm 토큰 (사용자 당)으로 완벽하게 작동합니다. 지금은 '주제'알림을 추가 할, 그래서 구독 추가 한 : Android : Firebase "topics"알림이 내 앱에서 처리되지 않습니다.

public class MyInstanceIDListenerService extends FirebaseInstanceIdService { 

    private static final String TAG = LogUtils.makeLogTag(MyInstanceIDListenerService.class); 

    /** 
    * Called if InstanceID token is updated. This may occur if the security of 
    * the previous token had been compromised. Note that this is also called 
    * when the InstanceID token is initially generated, so this is where 
    * you retrieve the token. 
    */ 
    @Override 
    public void onTokenRefresh() { 
      // Get updated InstanceID token. 
      String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
      LogUtils.LOGD(TAG, "Refreshed FCM token: " + refreshedToken); 
      ... 
      subscribeTopics();       
    } 

    /** 
    * Subscribe to any FCM topics of interest, as defined by the TOPICS constant. 
    */ 
    private void subscribeTopics() { 
     for (String topic : MyFcmListenerService.TOPICS) { 
      FirebaseMessaging.getInstance().subscribeToTopic(topic); 
     } 
    } 
} 

그리고 내 수신기

알림 이런 종류의 처리하지 않습니다

public class MyFcmListenerService extends FirebaseMessagingService { 

    private static final String TAG = LogUtils.makeLogTag(MyFcmListenerService.class); 

    // Topics 
    public static final String TOPIC = "/topics/"; 
    public static final String UPGRADE = "upgrade"; 
    public static final String[] TOPICS = {UPGRADE}; 

    // Downstream type messages 
    public static final String PROFIL = "profil"; 
    ... 


    protected WebServicesModule getWebServicesModule() { 
     return MyApplication.getInstance().getDataHolder().getWebServicesModule(); 
    } 

    public MyFcmListenerService() { 
    } 

    /** 
    * Called when message is received. 
    * 
    * @param message 
    */ 
    @Override 
    public void onMessageReceived(RemoteMessage message) { 

     String from = message.getFrom(); 
     Map data = message.getData(); 

     LogUtils.LOGD(TAG, "[FCM] Topic message received from [" + from + "]"); 

     ... 

onMessageReceived 기능은()이다 호출되지 나는 (우편 배달부)에서이 통지를 보낼 때이 헤더 구성

enter image description here

을 :

enter image description here

여러분의 도움에 감사드립니다!

답변

0

onTokenRefresh()이 호출 될 때 주제에 가입 중입니다. 이 메소드는 드물게 호출되며 only for specific events입니다. 다른 이벤트에서 주제 구독을 수행하십시오 (예 : onCreate(), 앱의 MainActivity).