FirebaseMessagingService onMessageReceived ошибка переопределения - PullRequest
0 голосов
/ 09 октября 2019

Класс:

class SubscriptionMessageService : FirebaseMessagingService() {

companion object {
    private val TAG = SubscriptionMessageService::class.java.simpleName
    private const val REMOTE_MESSAGE_SUBSCRIPTIONS_KEY = "currentStatus"
}

override fun onMessageReceived(remoteMessage: RemoteMessage?) {
    remoteMessage?.data?.let {
        val data = it
        if (data.isNotEmpty()) {
            var result: List<SubscriptionStatus>? = null
            if (REMOTE_MESSAGE_SUBSCRIPTIONS_KEY in data) {
                result = data[REMOTE_MESSAGE_SUBSCRIPTIONS_KEY]?.let {
                    SubscriptionStatus.listFromJsonString(it)
                }
            }
            if (result == null) {
                Log.e(TAG, "Invalid subscription data")
            } else {
                val app = application as SubApp
                app.repository.updateSubscriptionsFromNetwork(result)
            }
        }
    }
}
}

Ошибка: «onMessageReceived» ничего не переопределяет

Ссылка на Github: https://github.com/googlesamples/android-play-billing/blob/master/ClassyTaxi/android/ClassyTaxi/app/src/main/java/com/example/subscriptions/data/network/firebase/SubscriptionMessageService.kt

Ответы [ 2 ]

1 голос
/ 09 октября 2019

RemoteMessage не обнуляется, вы должны изменить это

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    val data = remoteMessage.data
    if (data.isNotEmpty()) {
        var result: List<SubscriptionStatus>? = null
        if (REMOTE_MESSAGE_SUBSCRIPTIONS_KEY in data) {
            result = data[REMOTE_MESSAGE_SUBSCRIPTIONS_KEY]?.let {
                SubscriptionStatus.listFromJsonString(it)
            }
        }
        if (result == null) {
            Log.e(TAG, "Invalid subscription data")
        } else {
            val app = application as SubApp
            app.repository.updateSubscriptionsFromNetwork(result)
        }
    }
}
0 голосов
/ 09 октября 2019

У меня это работает так:

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    remoteMessage?.data?.let {
        val data = it
        if (data.isNotEmpty()) {
            var result: List<SubscriptionStatus>? = null
            if (REMOTE_MESSAGE_SUBSCRIPTIONS_KEY in data) {
                result = data[REMOTE_MESSAGE_SUBSCRIPTIONS_KEY]?.let {
                    SubscriptionStatus.listFromJsonString(it)
                }
            }
            if (result == null) {
                Log.e(TAG, "Invalid subscription data")
            } else {
                val app = application as SubApp
                app.repository.updateSubscriptionsFromNetwork(result)
            }
        }
    }
}
...