XuqmGroup-AndroidSDK/sdk-push/src/main/java/com/xuqm/sdk/push/PushSDK.kt

45 行
1.3 KiB
Kotlin

2026-04-21 22:07:29 +08:00
package com.xuqm.sdk.push
import android.content.Context
import com.xuqm.sdk.XuqmSDK
import com.xuqm.sdk.network.ApiClient
import com.xuqm.sdk.push.api.PushApi
import com.xuqm.sdk.push.api.RegisterDeviceRequest
2026-04-21 22:07:29 +08:00
import com.xuqm.sdk.utils.DeviceUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
object PushSDK {
private val api: PushApi by lazy { ApiClient.create() }
private val scope = CoroutineScope(Dispatchers.IO)
fun registerDevice(context: Context, userId: String) {
2026-04-21 22:07:29 +08:00
XuqmSDK.requireInit()
val vendor = DeviceUtils.getVendor()
val deviceId = DeviceUtils.getDeviceId(context)
2026-04-21 22:07:29 +08:00
scope.launch {
runCatching {
api.registerDevice(
RegisterDeviceRequest(
userId = userId,
appId = XuqmSDK.appId,
platform = "Android",
vendor = vendor,
pushToken = "",
deviceId = deviceId,
)
)
2026-04-21 22:07:29 +08:00
}
}
}
fun unregisterDevice(userId: String) {
2026-04-21 22:07:29 +08:00
XuqmSDK.requireInit()
scope.launch {
runCatching { api.unregisterDevice(XuqmSDK.appId, userId) }
2026-04-21 22:07:29 +08:00
}
}
}