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:
parent
7c7fbab3ef
commit
e20e8c7ad7
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* <service android:name="com.vivo.push.sdk.service.CommandClientService">
|
||||
* 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) {}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue