fix(push): 修复 VIVO push initialize 调用失败问题
PushClient.initialize() 无参版本为 private,v4.x SDK 公开方法为 initialize(PushConfig)。通过反射构建 PushConfig.Builder().build() 后调用正确的公开方法。同时移除已废弃的 persistRegId()——v4.x SDK 的 regId 通过 onReceiveRegId 回调异步返回,不再提供同步 getRegId()。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
fc43885f1e
当前提交
e6fcdefacd
@ -2,7 +2,6 @@ package com.xuqm.sdk.push.vendor
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.xuqm.sdk.push.PushSDK
|
|
||||||
import com.xuqm.sdk.push.model.PushVendor
|
import com.xuqm.sdk.push.model.PushVendor
|
||||||
import com.xuqm.sdk.push.model.PushVendorConfig
|
import com.xuqm.sdk.push.model.PushVendorConfig
|
||||||
import java.lang.reflect.Proxy
|
import java.lang.reflect.Proxy
|
||||||
@ -38,7 +37,18 @@ class VivoPushService : PushVendorInterface {
|
|||||||
val pushClientClass = Class.forName("com.vivo.push.PushClient")
|
val pushClientClass = Class.forName("com.vivo.push.PushClient")
|
||||||
val instance = pushClientClass.getMethod("getInstance", Context::class.java)
|
val instance = pushClientClass.getMethod("getInstance", Context::class.java)
|
||||||
.invoke(null, context)
|
.invoke(null, context)
|
||||||
pushClientClass.getMethod("initialize").invoke(instance)
|
|
||||||
|
// v4.x SDK: initialize(PushConfig) — the no-arg overload is private
|
||||||
|
val builderClass = Class.forName("com.vivo.push.PushConfig\$Builder")
|
||||||
|
val builder = builderClass.getConstructor().newInstance()
|
||||||
|
runCatching {
|
||||||
|
builderClass.getMethod("agreePrivacyStatement", Boolean::class.javaPrimitiveType)
|
||||||
|
.invoke(builder, true)
|
||||||
|
}
|
||||||
|
val pushConfig = builderClass.getMethod("build").invoke(builder)
|
||||||
|
val pushConfigClass = Class.forName("com.vivo.push.PushConfig")
|
||||||
|
pushClientClass.getMethod("initialize", pushConfigClass).invoke(instance, pushConfig)
|
||||||
|
|
||||||
val listenerClass = Class.forName("com.vivo.push.IPushActionListener")
|
val listenerClass = Class.forName("com.vivo.push.IPushActionListener")
|
||||||
val listener = Proxy.newProxyInstance(
|
val listener = Proxy.newProxyInstance(
|
||||||
listenerClass.classLoader,
|
listenerClass.classLoader,
|
||||||
@ -47,19 +57,14 @@ class VivoPushService : PushVendorInterface {
|
|||||||
if (method.name == "onStateChanged") {
|
if (method.name == "onStateChanged") {
|
||||||
val state = args?.firstOrNull() as? Int
|
val state = args?.firstOrNull() as? Int
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
persistRegId(context, pushClientClass, instance)
|
Log.i(TAG, "Vivo push turnOnPush success, awaiting onReceiveRegId callback")
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Vivo push turnOnPush state=$state")
|
Log.e(TAG, "Vivo push turnOnPush failed: state=$state")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
runCatching {
|
pushClientClass.getMethod("turnOnPush", listenerClass).invoke(instance, listener)
|
||||||
pushClientClass.getMethod("turnOnPush", listenerClass)
|
|
||||||
.invoke(instance, listener)
|
|
||||||
}.onFailure {
|
|
||||||
persistRegId(context, pushClientClass, instance)
|
|
||||||
}
|
|
||||||
Log.i(TAG, "Vivo push registration requested")
|
Log.i(TAG, "Vivo push registration requested")
|
||||||
}.onFailure { error ->
|
}.onFailure { error ->
|
||||||
Log.e(TAG, "Vivo push registration failed: ${error.message}")
|
Log.e(TAG, "Vivo push registration failed: ${error.message}")
|
||||||
@ -81,18 +86,4 @@ class VivoPushService : PushVendorInterface {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "VivoPushService"
|
private const val TAG = "VivoPushService"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun persistRegId(
|
|
||||||
context: Context,
|
|
||||||
pushClientClass: Class<*>,
|
|
||||||
instance: Any,
|
|
||||||
) {
|
|
||||||
val regId = runCatching {
|
|
||||||
pushClientClass.getMethod("getRegId").invoke(instance) as? String
|
|
||||||
}.getOrNull()
|
|
||||||
if (!regId.isNullOrBlank()) {
|
|
||||||
PushSDK.updateNativePushToken(context, vendor, regId)
|
|
||||||
Log.i(TAG, "Vivo push token acquired")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户