fix(android): migrate OPPO & vivo push SDKs to new API versions

- OPPO HeytapPush V3.7.1: fix ICallBackResultService package (mode→callback),
  update init() signature (remove appKey/appSecret), update all callback
  method signatures, remove deprecated onReceiveMessage/onNotificationTapped
- vivo Push v4.1.3.0: replace OpenIMInterface+OpenClientPushManager with
  OpenClientPushMessageReceiver+PushClient, async getRegId

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-10 08:09:22 -07:00
parent 7c7fbab3ef
commit e20e8c7ad7
3 changed files with 38 additions and 53 deletions

View File

@ -9,7 +9,8 @@ import com.iagent.it0_app.push.OppoPushService
import com.iagent.it0_app.push.VivoPushChannel import com.iagent.it0_app.push.VivoPushChannel
import com.xiaomi.mipush.sdk.MiPushClient import com.xiaomi.mipush.sdk.MiPushClient
import com.heytap.msp.push.HeytapPushManager import com.heytap.msp.push.HeytapPushManager
import com.vivo.push.sdk.OpenClientPushManager import com.vivo.push.PushClient
import com.vivo.push.PushConfig
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
@ -108,9 +109,10 @@ class MainActivity : FlutterActivity() {
when (call.method) { when (call.method) {
"getToken" -> { "getToken" -> {
try { try {
val mgr = OpenClientPushManager.getInstance(this) val config = PushConfig.Builder().agreePrivacyStatement(true).build()
mgr.initialize() PushClient.getInstance(this).initialize(config)
result.success(VivoPushChannel.getToken(this)) VivoPushChannel.getToken(this)
result.success(null)
} catch (e: Exception) { result.error("VIVO_PUSH_ERROR", e.message, null) } } catch (e: Exception) { result.error("VIVO_PUSH_ERROR", e.message, null) }
} }
else -> result.notImplemented() else -> result.notImplemented()

View File

@ -2,60 +2,44 @@ package com.iagent.it0_app.push
import android.content.Context import android.content.Context
import com.heytap.msp.push.HeytapPushManager import com.heytap.msp.push.HeytapPushManager
import com.heytap.msp.push.mode.ICallBackResultService import com.heytap.msp.push.callback.ICallBackResultService
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
/** /**
* OPPO / OnePlus / Realme push integration via HeytapPush SDK. * OPPO / OnePlus / Realme push integration via HeytapPush SDK V3.7.1+.
* *
* Initialization (called from MainActivity.onCreate): * Initialization (called from MainActivity.onCreate):
* HeytapPushManager.init(context, OPPO_APP_KEY, OPPO_APP_SECRET, true) * OppoPushService.init(context, OPPO_APP_KEY, OPPO_APP_SECRET)
* HeytapPushManager.register(context, OPPO_APP_KEY, OPPO_APP_SECRET, OppoPushCallback)
*/ */
object OppoPushService { object OppoPushService {
private var channel: MethodChannel? = null var channel: MethodChannel? = null
fun register(channel: MethodChannel) { fun register(channel: MethodChannel) {
this.channel = channel this.channel = channel
} }
fun init(context: Context, appKey: String, appSecret: String) { fun init(context: Context, appKey: String, appSecret: String) {
HeytapPushManager.init(context, appKey, appSecret, true) HeytapPushManager.init(context, true)
HeytapPushManager.register(context, appKey, appSecret, OppoPushCallback) HeytapPushManager.register(context, appKey, appSecret, OppoPushCallback)
} }
fun getToken(): String? = HeytapPushManager.getRegisterID() fun getToken(): String? = HeytapPushManager.getRegisterID()
val callback = OppoPushCallback
} }
object OppoPushCallback : ICallBackResultService { object OppoPushCallback : ICallBackResultService {
override fun onRegister(responseCode: Int, registerID: String?) { override fun onRegister(responseCode: Int, userId: String, pushToken: String, extra: String) {
if (responseCode == 0 && !registerID.isNullOrEmpty()) { if (responseCode == 0 && pushToken.isNotEmpty()) {
OppoPushService.channel?.invokeMethod("onTokenRefresh", registerID) OppoPushService.channel?.invokeMethod("onTokenRefresh", pushToken)
} }
} }
override fun onUnRegister(responseCode: Int) {} override fun onUnRegister(responseCode: Int, userId: String, extra: String) {}
override fun onGetPushStatus(responseCode: Int, status: Int) {} override fun onGetPushStatus(responseCode: Int, status: Int) {}
override fun onGetNotificationStatus(responseCode: Int, status: Int) {} override fun onGetNotificationStatus(responseCode: Int, status: Int) {}
override fun onSetPushTime(responseCode: Int, pushTime: String?) {} override fun onSetPushTime(responseCode: Int, extra: String) {}
override fun onReceiveMessage(message: com.heytap.msp.push.mode.MessagePayload?) { override fun onError(responseCode: Int, userId: String, pushToken: String, extra: String) {}
if (message == null) return
OppoPushService.channel?.invokeMethod(
"onMessageReceived",
mapOf(
"title" to (message.title ?: ""),
"body" to (message.body ?: "")
)
)
}
override fun onNotificationTapped(message: com.heytap.msp.push.mode.MessagePayload?) {
OppoPushService.channel?.invokeMethod("onNotificationTap", null)
}
} }

View File

@ -1,23 +1,22 @@
package com.iagent.it0_app.push package com.iagent.it0_app.push
import android.content.Context import android.content.Context
import android.content.Intent import com.vivo.push.PushClient
import com.vivo.push.sdk.OpenClientPushManager import com.vivo.push.PushConfig
import com.vivo.push.sdk.OpenIMInterface import com.vivo.push.listener.IPushQueryActionListener
import com.vivo.push.model.UPSNotificationMessage
import com.vivo.push.model.UnvarnishedMessage
import com.vivo.push.sdk.OpenClientPushMessageReceiver
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
/** /**
* vivo Push receiver. * vivo Push receiver (SDK v4.1+).
* *
* Implements OpenIMInterface for push callbacks. * Registered as a BroadcastReceiver in AndroidManifest.xml.
* Initialization (called from MainActivity.onCreate): * Initialization (called from MainActivity):
* OpenClientPushManager.getInstance(context).initialize() * PushClient.getInstance(context).initialize(PushConfig.Builder().agreePrivacyStatement(true).build())
*
* Note: vivo push manifest registration is handled by the SDK via
* <service android:name="com.vivo.push.sdk.service.CommandClientService">
* declared in the SDK's manifest (merged automatically via AAR).
*/ */
class VivoPushReceiver : OpenIMInterface { class VivoPushReceiver : OpenClientPushMessageReceiver() {
override fun onReceiveRegId(context: Context?, regId: String?) { override fun onReceiveRegId(context: Context?, regId: String?) {
if (!regId.isNullOrEmpty()) { if (!regId.isNullOrEmpty()) {
@ -25,21 +24,16 @@ class VivoPushReceiver : OpenIMInterface {
} }
} }
override fun onReceivePassThroughMessage(context: Context?, message: com.vivo.push.model.UPSNotificationMessage?) { override fun onTransmissionMessage(context: Context, message: UnvarnishedMessage) {
if (message == null) return
VivoPushChannel.send( VivoPushChannel.send(
"onMessageReceived", "onMessageReceived",
mapOf("title" to (message.title ?: ""), "body" to (message.content ?: "")) mapOf("title" to "", "body" to (message.message ?: ""))
) )
} }
override fun onNotificationMessageClicked(context: Context?, intent: Intent?) { override fun onNotificationMessageClicked(context: Context, message: UPSNotificationMessage) {
VivoPushChannel.send("onNotificationTap", null) VivoPushChannel.send("onNotificationTap", null)
} }
override fun onNotificationMessageArrived(context: Context?, message: com.vivo.push.model.UPSNotificationMessage?) {
// system tray handles display
}
} }
object VivoPushChannel { object VivoPushChannel {
@ -53,7 +47,12 @@ object VivoPushChannel {
channel?.invokeMethod(method, args) channel?.invokeMethod(method, args)
} }
fun getToken(context: Context): String? { fun getToken(context: Context) {
return OpenClientPushManager.getInstance(context).regId PushClient.getInstance(context).getRegId(object : IPushQueryActionListener {
override fun onSuccess(regId: String) {
if (regId.isNotEmpty()) send("onTokenRefresh", regId)
}
override fun onFail(errorCode: Int) {}
})
} }
} }