Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
a6f7f0d0
提交
a6f7f0d0
authored
2月 05, 2021
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass extMessage when cold launch FlutterApp from h5.
上级
36ab4af3
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
145 行增加
和
33 行删除
+145
-33
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+12
-6
FluwxRequestHandler.kt
...n/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
+77
-4
WXAPiHandler.kt
...src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
+21
-3
FluwxWXEntryActivity.kt
...ain/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
+17
-12
AndroidManifest.xml
example/android/app/src/main/AndroidManifest.xml
+12
-8
MainActivity.kt
.../src/main/kotlin/com/jarvan/fluwx_example/MainActivity.kt
+6
-0
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
a6f7f0d0
...
...
@@ -16,7 +16,7 @@ import io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.PluginRegistry
/** FluwxPlugin */
public
class
FluwxPlugin
:
FlutterPlugin
,
MethodCallHandler
,
ActivityAware
{
class
FluwxPlugin
:
FlutterPlugin
,
MethodCallHandler
,
ActivityAware
{
companion
object
{
@JvmStatic
...
...
@@ -39,12 +39,18 @@ public class FluwxPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private
var
authHandler
:
FluwxAuthHandler
?
=
null
private
var
fluwxChannel
:
MethodChannel
?
=
null
override
fun
onAttachedToEngine
(
@NonNull
flutterPluginBinding
:
FlutterPlugin
.
FlutterPluginBinding
)
{
val
channel
=
MethodChannel
(
flutterPluginBinding
.
binaryMessenger
,
"com.jarvanmo/fluwx"
)
channel
.
setMethodCallHandler
(
this
)
FluwxResponseHandler
.
setMethodChannel
(
channel
)
FluwxRequestHandler
.
setMethodChannel
(
channel
)
authHandler
=
FluwxAuthHandler
(
channel
)
if
(
fluwxChannel
==
null
)
{
fluwxChannel
=
MethodChannel
(
flutterPluginBinding
.
binaryMessenger
,
"com.jarvanmo/fluwx"
)
fluwxChannel
?.
setMethodCallHandler
(
this
)
}
fluwxChannel
?.
let
{
FluwxResponseHandler
.
setMethodChannel
(
it
)
FluwxRequestHandler
.
setMethodChannel
(
it
)
authHandler
=
FluwxAuthHandler
(
it
)
}
shareHandler
=
FluwxShareHandlerEmbedding
(
flutterPluginBinding
.
flutterAssets
,
flutterPluginBinding
.
applicationContext
)
}
...
...
android/src/main/kotlin/com/jarvan/fluwx/handlers/FluwxRequestHandler.kt
浏览文件 @
a6f7f0d0
...
...
@@ -14,26 +14,98 @@
* limitations under the License.
*/
package
com.jarvan.fluwx.handlers
import
android.app.Activity
import
android.content.Context
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.os.Bundle
import
android.util.Log
import
com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import
io.flutter.plugin.common.MethodChannel
import
com.tencent.mm.opensdk.modelbase.BaseReq
import
java.lang.Exception
object
FluwxRequestHandler
{
private
const
val
KEY_FLUWX_REQUEST_INFO_BUNDLE
=
"KEY_FLUWX_REQUEST_INFO_BUNDLE"
var
customOnReqDelegate
:
((
baseReq
:
BaseReq
,
activity
:
Activity
)
->
Unit
)?
=
null
private
var
channel
:
MethodChannel
?
=
null
fun
setMethodChannel
(
channel
:
MethodChannel
)
{
FluwxRequestHandler
.
channel
=
channel
}
fun
handleRequest
(
req
:
BaseReq
)
{
fun
handleRequestInfoFromIntent
(
intent
:
Intent
)
{
intent
.
getBundleExtra
(
KEY_FLUWX_REQUEST_INFO_BUNDLE
)
?.
run
{
val
type
=
getInt
(
"_wxapi_command_type"
,
-
9999
)
if
(
type
==
4
)
{
handleShowMessageFromWXBundle
(
this
)
}
}
}
private
fun
handleShowMessageFromWXBundle
(
bundle
:
Bundle
)
=
handleWXShowMessageFromWX
(
ShowMessageFromWX
.
Req
(
bundle
))
private
fun
handleRequest
(
req
:
BaseReq
)
{
when
(
req
)
{
is
ShowMessageFromWX
.
Req
->
hanleWXShowMessageFromWX
(
req
)
is
ShowMessageFromWX
.
Req
->
han
d
leWXShowMessageFromWX
(
req
)
}
}
private
fun
han
leWXShowMessageFromWX
(
req
:
ShowMessageFromWX
.
Req
)
{
private
fun
hand
leWXShowMessageFromWX
(
req
:
ShowMessageFromWX
.
Req
)
{
val
result
=
mapOf
(
"extMsg"
to
req
.
message
.
messageExt
,
)
"extMsg"
to
req
.
message
.
messageExt
,
)
channel
?.
invokeMethod
(
"onWXShowMessageFromWX"
,
result
)
}
private
fun
defaultOnReqDelegate
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
// FIXME: 可能是官方的Bug,从微信拉起APP的Intent类型不对,无法跳转回Flutter Activity
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
if
(
baseReq
.
type
==
4
)
{
// com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4
if
(
WXAPiHandler
.
wxApiRegistered
)
{
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
)
}
}
}
fun
onReq
(
baseReq
:
BaseReq
,
activity
:
Activity
)
{
try
{
val
appInfo
=
activity
.
packageManager
.
getApplicationInfo
(
activity
.
packageName
,
PackageManager
.
GET_META_DATA
)
val
defaultHandle
=
appInfo
.
metaData
.
getBoolean
(
"handleWeChatRequestByFluwx"
,
true
)
if
(
defaultHandle
)
{
defaultOnReqDelegate
(
baseReq
,
activity
)
}
else
{
customOnReqDelegate
?.
invoke
(
baseReq
,
activity
)
}
}
catch
(
e
:
Exception
)
{
Log
.
i
(
"Fluwx"
,
"can't load meta-data handleWeChatRequestByFluwx"
)
}
}
private
fun
startSpecifiedActivity
(
action
:
String
,
activity
:
Activity
,
bundle
:
Bundle
?
=
null
,
bundleKey
:
String
?
=
null
)
{
Intent
(
action
).
run
{
bundleKey
?.
let
{
putExtra
(
bundleKey
,
bundle
)
}
addFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
)
activity
.
packageManager
?.
let
{
resolveActivity
(
it
)
?.
also
{
activity
.
startActivity
(
this
)
activity
.
finish
()
}
}
}
}
private
fun
defaultFlutterActivityAction
(
context
:
Context
):
String
=
"$context.packageName.FlutterActivity"
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/handlers/WXAPiHandler.kt
浏览文件 @
a6f7f0d0
...
...
@@ -30,6 +30,18 @@ object WXAPiHandler {
private
var
context
:
Context
?
=
null
private
var
registered
:
Boolean
=
false
val
wxApiRegistered
get
()
=
registered
fun
setupWxApi
(
appId
:
String
,
context
:
Context
,
force
:
Boolean
=
true
):
Boolean
{
if
(
force
||
!
registered
)
{
setContext
(
context
)
registerWxAPIInternal
(
appId
,
context
)
}
return
registered
}
fun
setContext
(
context
:
Context
?)
{
WXAPiHandler
.
context
=
context
}
...
...
@@ -51,9 +63,9 @@ object WXAPiHandler {
return
}
val
api
=
WXAPIFactory
.
createWXAPI
(
context
?.
applicationContext
,
appId
)
val
registered
=
api
.
registerApp
(
appId
)
wxApi
=
api
context
?.
let
{
registerWxAPIInternal
(
appId
,
it
)
}
result
.
success
(
registered
)
}
...
...
@@ -64,6 +76,11 @@ object WXAPiHandler {
}
else
{
result
.
success
(
wxApi
?.
isWXAppInstalled
)
}
}
private
fun
registerWxAPIInternal
(
appId
:
String
,
context
:
Context
)
{
val
api
=
WXAPIFactory
.
createWXAPI
(
context
.
applicationContext
,
appId
)
registered
=
api
.
registerApp
(
appId
)
wxApi
=
api
}
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/wxapi/FluwxWXEntryActivity.kt
浏览文件 @
a6f7f0d0
...
...
@@ -23,7 +23,6 @@ import com.jarvan.fluwx.handlers.FluwxRequestHandler
import
com.jarvan.fluwx.handlers.WXAPiHandler
import
com.tencent.mm.opensdk.modelbase.BaseReq
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
com.tencent.mm.opensdk.modelmsg.ShowMessageFromWX
import
com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
...
...
@@ -38,7 +37,7 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
WXAPiHandler
.
wxApi
?.
handleIntent
(
intent
,
this
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
startSpecifiedActivity
()
startSpecifiedActivity
(
defaultFlutterActivityAction
()
)
finish
()
}
}
...
...
@@ -52,7 +51,7 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
WXAPiHandler
.
wxApi
?.
handleIntent
(
intent
,
this
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
startSpecifiedActivity
()
startSpecifiedActivity
(
defaultFlutterActivityAction
()
)
finish
()
}
}
...
...
@@ -61,11 +60,7 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
override
fun
onReq
(
baseReq
:
BaseReq
)
{
// FIXME: 可能是官方的Bug,从微信拉起APP的Intent类型不对,无法跳转回Flutter Activity
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7
if
(
baseReq
.
type
==
4
)
{
// com.tencent.mm.opensdk.constants.ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX = 4
FluwxRequestHandler
.
handleRequest
(
baseReq
)
startSpecifiedActivity
()
}
FluwxRequestHandler
.
onReq
(
baseReq
,
this
)
}
// 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法
...
...
@@ -74,11 +69,20 @@ open class FluwxWXEntryActivity : Activity(), IWXAPIEventHandler {
finish
()
}
private
fun
startSpecifiedActivity
()
{
Intent
(
"$packageName.FlutterActivity"
).
run
{
private
fun
startSpecifiedActivity
(
action
:
String
,
bundle
:
Bundle
?
=
null
,
bundleKey
:
String
?
=
null
)
{
Intent
(
action
).
run
{
bundleKey
?.
let
{
putExtra
(
bundleKey
,
bundle
)
}
addFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
)
startActivity
(
this
)
packageManager
?.
let
{
resolveActivity
(
packageManager
)
?.
also
{
startActivity
(
this
)
finish
()
}
}
}
finish
()
}
private
fun
defaultFlutterActivityAction
():
String
=
"$packageName.FlutterActivity"
}
\ No newline at end of file
example/android/app/src/main/AndroidManifest.xml
浏览文件 @
a6f7f0d0
...
...
@@ -5,22 +5,23 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application
android:name=
"io.flutter.app.FlutterApplication"
android:
label=
"fluwx_example
"
android:
icon=
"@mipmap/ic_launcher
"
>
android:
icon=
"@mipmap/ic_launcher
"
android:
label=
"fluwx_example
"
>
<activity
android:name=
".MainActivity"
android:launchMode=
"singleTop"
android:theme=
"@style/LaunchTheme"
android:configChanges=
"orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated=
"true"
android:launchMode=
"singleTop"
android:theme=
"@style/LaunchTheme"
android:windowSoftInputMode=
"adjustResize"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"${applicationId}.FlutterActivity"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"${applicationId}.FlutterActivity"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
...
...
@@ -28,5 +29,8 @@
<meta-data
android:name=
"flutterEmbedding"
android:value=
"2"
/>
<meta-data
android:name=
"handleWeChatRequestByFluwx"
android:value=
"false"
/>
</application>
</manifest>
example/android/app/src/main/kotlin/com/jarvan/fluwx_example/MainActivity.kt
浏览文件 @
a6f7f0d0
package
com.jarvan.fluwx_example
import
androidx.annotation.NonNull;
import
com.jarvan.fluwx.handlers.FluwxRequestHandler
import
com.jarvan.fluwx.handlers.WXAPiHandler
import
io.flutter.embedding.android.FlutterActivity
import
io.flutter.embedding.engine.FlutterEngine
import
io.flutter.plugins.GeneratedPluginRegistrant
...
...
@@ -8,5 +10,9 @@ import io.flutter.plugins.GeneratedPluginRegistrant
class
MainActivity
:
FlutterActivity
()
{
override
fun
configureFlutterEngine
(
@NonNull
flutterEngine
:
FlutterEngine
)
{
GeneratedPluginRegistrant
.
registerWith
(
flutterEngine
);
//If you didn't configure WxAPI, add the following code
WXAPiHandler
.
setupWxApi
(
"wxd930ea5d5a258f4f"
,
this
)
//Get Ext-Info from Intent.
FluwxRequestHandler
.
handleRequestInfoFromIntent
(
intent
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论