提交 304eafc4 authored 作者: JarvanMo's avatar JarvanMo

Merge commit 'a92350fc'

# Conflicts: # android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt # doc/LAUNCH_APP_FROM_H5_CN.md # example/android/app/src/main/AndroidManifest.xml # example/pubspec.lock # pubspec.yaml
package com.jarvan.fluwx
import android.content.Intent
import android.util.Log
import androidx.annotation.NonNull
import com.jarvan.fluwx.handlers.*
import com.tencent.mm.opensdk.modelbiz.SubscribeMessage
......@@ -16,11 +18,13 @@ import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry
/** FluwxPlugin */
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,PluginRegistry.NewIntentListener {
companion object {
var callingChannel:MethodChannel? = null
// 主动获取的启动参数
var extMsg:String? = null
@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
......@@ -43,6 +47,14 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private var fluwxChannel: MethodChannel? = null
private fun handelIntent(intent:Intent?){
val action = intent?.action
val dataString = intent?.dataString
if (Intent.ACTION_VIEW.equals(action)) {
extMsg = dataString
}
}
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
val channel = MethodChannel(flutterPluginBinding.binaryMessenger, "com.jarvanmo/fluwx")
channel.setMethodCallHandler(this)
......@@ -66,6 +78,7 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
call.method == "openWXApp" -> openWXApp(result)
call.method.startsWith("share") -> shareHandler?.share(call, result)
call.method == "isWeChatInstalled" -> WXAPiHandler.checkWeChatInstallation(result)
call.method == "getExtMsg" -> getExtMsg(result)
else -> result.notImplemented()
}
}
......@@ -81,10 +94,12 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
shareHandler?.permissionHandler = PermissionHandler(binding.activity)
handelIntent(binding.activity.intent)
}
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
WXAPiHandler.setContext(binding.activity.applicationContext)
handelIntent(binding.activity.intent)
shareHandler?.permissionHandler = PermissionHandler(binding.activity)
}
......@@ -92,6 +107,10 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
private fun getExtMsg(result: MethodChannel.Result) {
result.success(extMsg)
}
private fun pay(call: MethodCall, result: MethodChannel.Result) {
if (WXAPiHandler.wxApi == null) {
......@@ -187,4 +206,9 @@ class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
private fun openWXApp(result: MethodChannel.Result) = result.success(WXAPiHandler.wxApi?.openWXApp())
override fun onNewIntent(intent: Intent?): Boolean {
handelIntent(intent)
return false
}
}
......@@ -19,13 +19,15 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.core.content.ContextCompat.startActivity
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
import java.lang.Exception
import com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import java.security.cert.Extension
object FluwxRequestHandler {
private const val KEY_FLUWX_REQUEST_INFO_BUNDLE = "KEY_FLUWX_REQUEST_INFO_BUNDLE"
......@@ -53,6 +55,7 @@ object FluwxRequestHandler {
val result = mapOf(
"extMsg" to req.message.messageExt
)
FluwxPlugin.extMsg = req.message.messageExt;
FluwxPlugin.callingChannel?.invokeMethod("onWXShowMessageFromWX", result)
}
......@@ -65,9 +68,19 @@ object FluwxRequestHandler {
handleRequest(baseReq)
startSpecifiedActivity(defaultFlutterActivityAction(activity), activity = activity)
} else {
startSpecifiedActivity(defaultFlutterActivityAction(activity), bundle = Bundle().apply {
baseReq.toBundle(this)
}, bundleKey = KEY_FLUWX_REQUEST_INFO_BUNDLE, activity = activity)
when (baseReq) {
is ShowMessageFromWX.Req -> {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("wechatextmsg://${activity.packageName}/?extmsg=${baseReq.message.messageExt}"))
activity.startActivity(intent)
activity.finish()
WXAPiHandler.setCoolBool(false)
}catch (e:Exception) {
Log.i("fluwx","call scheme error:${e.toString()}")
}
}
}
}
}
}
......@@ -75,7 +88,7 @@ object FluwxRequestHandler {
fun onReq(baseReq: BaseReq, activity: Activity) {
try {
val packageManager = activity.packageManager
var appInfo = packageManager.getApplicationInfo(activity.packageName,PackageManager.GET_META_DATA)
var appInfo = packageManager.getApplicationInfo(activity.packageName, PackageManager.GET_META_DATA)
val defaultHandle = appInfo.metaData.getBoolean("handleWeChatRequestByFluwx", true)
if (defaultHandle) {
defaultOnReqDelegate(baseReq, activity)
......
......@@ -39,6 +39,7 @@
<action android:name="${applicationId}.FlutterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
......
......@@ -75,6 +75,15 @@ class ShareSelectorPage extends StatelessWidget {
return Center(
child: new ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlineButton(
onPressed: () async {
String extMsg = await getExtMsg();
print("extMsg:$extMsg\n");
},
child: const Text("Get ExtMessage")),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlineButton(
......
......@@ -4,6 +4,10 @@
#import "FluwxAuthHandler.h"
#import "FluwxShareHandler.h"
@interface FluwxPlugin()<WXApiManagerDelegate>
@property (strong,nonatomic)NSString *extMsg;
@end
@implementation FluwxPlugin
FluwxAuthHandler *_fluwxAuthHandler;
FluwxShareHandler *_fluwxShareHandler;
......@@ -23,6 +27,7 @@ FlutterMethodChannel *channel = nil;
FluwxPlugin *instance = [[FluwxPlugin alloc] initWithRegistrar:registrar methodChannel:channel];
[registrar addMethodCallDelegate:instance channel:channel];
[[FluwxResponseHandler defaultManager] setMethodChannel:channel];
[registrar addApplicationDelegate:instance];
#if TARGET_OS_IPHONE
}
......@@ -35,8 +40,8 @@ FlutterMethodChannel *channel = nil;
if (self) {
_fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar methodChannel:flutterMethodChannel];
_fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar];
[FluwxResponseHandler defaultManager].delegate = self;
}
return self;
}
......@@ -65,6 +70,8 @@ FlutterMethodChannel *channel = nil;
[self handleAutoDeductWithCall:call result:result];
}else if([@"authByPhoneLogin" isEqualToString:call.method]){
[_fluwxAuthHandler handleAuthByPhoneLogin:call result:result];
}else if([@"getExtMsg" isEqualToString:call.method]){
[self handelGetExtMsgWithCall:call result:result];
} else if ([call.method hasPrefix:@"share"]) {
[_fluwxShareHandler handleShare:call result:result];
} else {
......@@ -189,6 +196,10 @@ FlutterMethodChannel *channel = nil;
}];
}
- (void)handelGetExtMsgWithCall:(FlutterMethodCall *)call result:(FlutterResult)result {
result(self.extMsg);
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler defaultManager]];
......@@ -216,4 +227,8 @@ FlutterMethodChannel *channel = nil;
}
}
- (void)managerDidRecvLaunchFromWXReq:(LaunchFromWXReq *)request {
self.extMsg = request.message.messageExt;
}
@end
......@@ -82,6 +82,11 @@ Future<bool> registerWxApi(
});
}
// get ext Message
Future<String> getExtMsg() async {
return await _channel.invokeMethod("getExtMsg");
}
///Share your requests to WeChat.
///This depends on the actual type of [model].
///see [_shareModelMethodMapper] for detail.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论