mirror of
https://github.com/OpenFlutter/fluwx.git
synced 2025-08-06 06:46:02 +08:00
fix #338 on Android
This commit is contained in:
@ -19,14 +19,16 @@ import io.flutter.plugin.common.PluginRegistry
|
||||
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
||||
|
||||
companion object {
|
||||
|
||||
var callingChannel:MethodChannel? = null
|
||||
|
||||
@JvmStatic
|
||||
fun registerWith(registrar: PluginRegistry.Registrar) {
|
||||
val channel = MethodChannel(registrar.messenger(), "com.jarvanmo/fluwx")
|
||||
val authHandler = FluwxAuthHandler(channel)
|
||||
FluwxResponseHandler.setMethodChannel(channel)
|
||||
FluwxRequestHandler.setMethodChannel(channel)
|
||||
WXAPiHandler.setContext(registrar.activity().applicationContext)
|
||||
channel.setMethodCallHandler(FluwxPlugin().apply {
|
||||
this.fluwxChannel = channel
|
||||
this.authHandler = authHandler
|
||||
this.shareHandler = FluwxShareHandlerCompat(registrar).apply {
|
||||
permissionHandler = PermissionHandler(registrar.activity())
|
||||
@ -42,19 +44,15 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
|
||||
private var fluwxChannel: MethodChannel? = null
|
||||
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
if (fluwxChannel == null) {
|
||||
fluwxChannel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
|
||||
fluwxChannel?.setMethodCallHandler(this)
|
||||
}
|
||||
fluwxChannel?.let {
|
||||
FluwxResponseHandler.setMethodChannel(it)
|
||||
FluwxRequestHandler.setMethodChannel(it)
|
||||
authHandler = FluwxAuthHandler(it)
|
||||
}
|
||||
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
|
||||
channel.setMethodCallHandler(this)
|
||||
fluwxChannel = channel
|
||||
authHandler = FluwxAuthHandler(channel)
|
||||
shareHandler = FluwxShareHandlerEmbedding(flutterPluginBinding.flutterAssets, flutterPluginBinding.applicationContext)
|
||||
}
|
||||
|
||||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
||||
FluwxPlugin.callingChannel = fluwxChannel
|
||||
when {
|
||||
call.method == "registerApp" -> WXAPiHandler.registerApp(call, result)
|
||||
call.method == "sendAuth" -> authHandler?.sendAuth(call, result)
|
||||
|
@ -21,6 +21,7 @@ import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import com.jarvan.fluwx.FluwxPlugin
|
||||
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import com.tencent.mm.opensdk.modelbase.BaseReq
|
||||
@ -31,13 +32,6 @@ object FluwxRequestHandler {
|
||||
|
||||
var customOnReqDelegate: ((baseReq: BaseReq, activity: Activity) -> Unit)? = null
|
||||
|
||||
private var channel: MethodChannel? = null
|
||||
|
||||
fun setMethodChannel(channel: MethodChannel) {
|
||||
FluwxRequestHandler.channel = channel
|
||||
}
|
||||
|
||||
|
||||
fun handleRequestInfoFromIntent(intent: Intent) {
|
||||
intent.getBundleExtra(KEY_FLUWX_REQUEST_INFO_BUNDLE)?.run {
|
||||
val type = getInt("_wxapi_command_type", -9999)
|
||||
@ -59,7 +53,7 @@ object FluwxRequestHandler {
|
||||
val result = mapOf(
|
||||
"extMsg" to req.message.messageExt
|
||||
)
|
||||
channel?.invokeMethod("onWXShowMessageFromWX", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onWXShowMessageFromWX", result)
|
||||
}
|
||||
|
||||
private fun defaultOnReqDelegate(baseReq: BaseReq, activity: Activity) {
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.jarvan.fluwx.handlers
|
||||
|
||||
import com.jarvan.fluwx.FluwxPlugin
|
||||
import com.tencent.mm.opensdk.modelbase.BaseResp
|
||||
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
|
||||
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
|
||||
@ -25,17 +26,12 @@ import com.tencent.mm.opensdk.modelpay.PayResp
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
object FluwxResponseHandler {
|
||||
private var channel: MethodChannel? = null
|
||||
|
||||
private const val errStr = "errStr"
|
||||
private const val errCode = "errCode"
|
||||
private const val openId = "openId"
|
||||
private const val type = "type"
|
||||
|
||||
fun setMethodChannel(channel: MethodChannel) {
|
||||
FluwxResponseHandler.channel = channel
|
||||
}
|
||||
|
||||
fun handleResponse(response: BaseResp) {
|
||||
when (response) {
|
||||
is SendAuth.Resp -> handleAuthResponse(response)
|
||||
@ -56,7 +52,7 @@ object FluwxResponseHandler {
|
||||
"scene" to response.scene,
|
||||
type to response.type)
|
||||
|
||||
channel?.invokeMethod("onSubscribeMsgResp", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onSubscribeMsgResp", result)
|
||||
}
|
||||
|
||||
private fun handleLaunchMiniProgramResponse(response: WXLaunchMiniProgram.Resp) {
|
||||
@ -71,7 +67,7 @@ object FluwxResponseHandler {
|
||||
result["extMsg"] = response.extMsg
|
||||
}
|
||||
|
||||
channel?.invokeMethod("onLaunchMiniProgramResponse", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onLaunchMiniProgramResponse", result)
|
||||
}
|
||||
|
||||
private fun handlePayResp(response: PayResp) {
|
||||
@ -83,7 +79,7 @@ object FluwxResponseHandler {
|
||||
type to response.type,
|
||||
errCode to response.errCode
|
||||
)
|
||||
channel?.invokeMethod("onPayResponse", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onPayResponse", result)
|
||||
}
|
||||
|
||||
private fun handleSendMessageResp(response: SendMessageToWX.Resp) {
|
||||
@ -93,7 +89,7 @@ object FluwxResponseHandler {
|
||||
errCode to response.errCode,
|
||||
openId to response.openId)
|
||||
|
||||
channel?.invokeMethod("onShareResponse", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onShareResponse", result)
|
||||
}
|
||||
|
||||
private fun handleAuthResponse(response: SendAuth.Resp) {
|
||||
@ -108,7 +104,7 @@ object FluwxResponseHandler {
|
||||
"url" to response.url,
|
||||
type to response.type)
|
||||
|
||||
channel?.invokeMethod("onAuthResponse", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onAuthResponse", result)
|
||||
}
|
||||
|
||||
|
||||
@ -121,6 +117,6 @@ object FluwxResponseHandler {
|
||||
openId to response.openId,
|
||||
type to response.type)
|
||||
|
||||
channel?.invokeMethod("onWXOpenBusinessWebviewResponse", result)
|
||||
FluwxPlugin.callingChannel?.invokeMethod("onWXOpenBusinessWebviewResponse", result)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user