joh*_*o07 0 android in-app-purchase google-cloud-messaging
班级:
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)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:“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
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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1115 次 |
| 最近记录: |