From e20e8c7ad73ec25f780525a7226b6dd744933d91 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 10 Mar 2026 08:09:22 -0700 Subject: [PATCH] fix(android): migrate OPPO & vivo push SDKs to new API versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../kotlin/com/iagent/it0_app/MainActivity.kt | 10 +++-- .../iagent/it0_app/push/OppoPushService.kt | 38 +++++----------- .../iagent/it0_app/push/VivoPushReceiver.kt | 43 +++++++++---------- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/MainActivity.kt b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/MainActivity.kt index 00a53ce..6f285e2 100644 --- a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/MainActivity.kt +++ b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/MainActivity.kt @@ -9,7 +9,8 @@ import com.iagent.it0_app.push.OppoPushService import com.iagent.it0_app.push.VivoPushChannel import com.xiaomi.mipush.sdk.MiPushClient 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.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel @@ -108,9 +109,10 @@ class MainActivity : FlutterActivity() { when (call.method) { "getToken" -> { try { - val mgr = OpenClientPushManager.getInstance(this) - mgr.initialize() - result.success(VivoPushChannel.getToken(this)) + val config = PushConfig.Builder().agreePrivacyStatement(true).build() + PushClient.getInstance(this).initialize(config) + VivoPushChannel.getToken(this) + result.success(null) } catch (e: Exception) { result.error("VIVO_PUSH_ERROR", e.message, null) } } else -> result.notImplemented() diff --git a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/OppoPushService.kt b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/OppoPushService.kt index d9d5d7f..4ac86de 100644 --- a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/OppoPushService.kt +++ b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/OppoPushService.kt @@ -2,60 +2,44 @@ package com.iagent.it0_app.push import android.content.Context 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 /** - * OPPO / OnePlus / Realme push integration via HeytapPush SDK. + * OPPO / OnePlus / Realme push integration via HeytapPush SDK V3.7.1+. * * Initialization (called from MainActivity.onCreate): - * HeytapPushManager.init(context, OPPO_APP_KEY, OPPO_APP_SECRET, true) - * HeytapPushManager.register(context, OPPO_APP_KEY, OPPO_APP_SECRET, OppoPushCallback) + * OppoPushService.init(context, OPPO_APP_KEY, OPPO_APP_SECRET) */ object OppoPushService { - private var channel: MethodChannel? = null + var channel: MethodChannel? = null fun register(channel: MethodChannel) { this.channel = channel } fun init(context: Context, appKey: String, appSecret: String) { - HeytapPushManager.init(context, appKey, appSecret, true) + HeytapPushManager.init(context, true) HeytapPushManager.register(context, appKey, appSecret, OppoPushCallback) } fun getToken(): String? = HeytapPushManager.getRegisterID() - - val callback = OppoPushCallback } object OppoPushCallback : ICallBackResultService { - override fun onRegister(responseCode: Int, registerID: String?) { - if (responseCode == 0 && !registerID.isNullOrEmpty()) { - OppoPushService.channel?.invokeMethod("onTokenRefresh", registerID) + override fun onRegister(responseCode: Int, userId: String, pushToken: String, extra: String) { + if (responseCode == 0 && pushToken.isNotEmpty()) { + 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 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?) { - 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) - } + override fun onError(responseCode: Int, userId: String, pushToken: String, extra: String) {} } diff --git a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/VivoPushReceiver.kt b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/VivoPushReceiver.kt index b6dab61..9e92307 100644 --- a/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/VivoPushReceiver.kt +++ b/it0_app/android/app/src/main/kotlin/com/iagent/it0_app/push/VivoPushReceiver.kt @@ -1,23 +1,22 @@ package com.iagent.it0_app.push import android.content.Context -import android.content.Intent -import com.vivo.push.sdk.OpenClientPushManager -import com.vivo.push.sdk.OpenIMInterface +import com.vivo.push.PushClient +import com.vivo.push.PushConfig +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 /** - * vivo Push receiver. + * vivo Push receiver (SDK v4.1+). * - * Implements OpenIMInterface for push callbacks. - * Initialization (called from MainActivity.onCreate): - * OpenClientPushManager.getInstance(context).initialize() - * - * Note: vivo push manifest registration is handled by the SDK via - * - * declared in the SDK's manifest (merged automatically via AAR). + * Registered as a BroadcastReceiver in AndroidManifest.xml. + * Initialization (called from MainActivity): + * PushClient.getInstance(context).initialize(PushConfig.Builder().agreePrivacyStatement(true).build()) */ -class VivoPushReceiver : OpenIMInterface { +class VivoPushReceiver : OpenClientPushMessageReceiver() { override fun onReceiveRegId(context: Context?, regId: String?) { if (!regId.isNullOrEmpty()) { @@ -25,21 +24,16 @@ class VivoPushReceiver : OpenIMInterface { } } - override fun onReceivePassThroughMessage(context: Context?, message: com.vivo.push.model.UPSNotificationMessage?) { - if (message == null) return + override fun onTransmissionMessage(context: Context, message: UnvarnishedMessage) { VivoPushChannel.send( "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) } - - override fun onNotificationMessageArrived(context: Context?, message: com.vivo.push.model.UPSNotificationMessage?) { - // system tray handles display - } } object VivoPushChannel { @@ -53,7 +47,12 @@ object VivoPushChannel { channel?.invokeMethod(method, args) } - fun getToken(context: Context): String? { - return OpenClientPushManager.getInstance(context).regId + fun getToken(context: Context) { + PushClient.getInstance(context).getRegId(object : IPushQueryActionListener { + override fun onSuccess(regId: String) { + if (regId.isNotEmpty()) send("onTokenRefresh", regId) + } + override fun onFail(errorCode: Int) {} + }) } }