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