Android:Firebase"主题"通知无法处理我的应用

时间:2017-11-26 11:38:25

标签: android firebase firebase-cloud-messaging

使用特定的fcm令牌(每个用户),它可以很好地工作。现在我想添加"主题"通知,所以我添加了订阅:

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 + "]");

       ...

当我发送此通知时(来自Postman),从不调用onMessageReceived()函数:

enter image description here

使用此标头配置:

enter image description here

感谢大家的帮助!

0 个答案:

没有答案