改包名com.aiosman.ravenow

This commit is contained in:
2024-11-17 20:07:42 +08:00
parent 914cfca6be
commit 074244c0f8
168 changed files with 897 additions and 970 deletions

View File

@@ -0,0 +1,58 @@
package com.aiosman.ravenow
import android.content.Context
import android.util.Log
import cn.jpush.android.api.JPushInterface
import com.aiosman.ravenow.data.AccountService
import com.aiosman.ravenow.data.AccountServiceImpl
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
object Messaging {
fun registerDevice(scope: CoroutineScope, context: Context) {
registerJpush(scope, context)
// registerFCM(scope)
}
suspend fun unregisterDevice(context: Context) {
unregisterJpush(context)
}
fun registerJpush(scope: CoroutineScope, context: Context) {
val accountService: AccountService = AccountServiceImpl()
val regId = JPushInterface.getRegistrationID(context)
scope.launch {
accountService.registerMessageChannel(client = "jpush", identifier = regId)
}
}
private suspend fun unregisterJpush(context: Context) {
val accountService: AccountService = AccountServiceImpl()
val regId = JPushInterface.getRegistrationID(context)
accountService.unregisterMessageChannel(client = "jpush", identifier = regId)
}
fun registerFCM(scope: CoroutineScope) {
val accountService: AccountService = AccountServiceImpl()
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("Pushing", "Fetching FCM registration token failed", task.exception)
return@OnCompleteListener
}
// Get new FCM registration token
val token = task.result
// Log and toast
Log.d("Pushing", token)
scope.launch {
accountService.registerMessageChannel(client = "fcm", token)
}
})
}
}