分享到微信的h5网页中点击调起app
1.引入第三方包fluwx:3.13.1
2.在app首页注册微信开放sdk、调用获取开放标签的方法
_initFluwx() async {
//注册
await registerWxApi(appId: 'wxadlklakd5dkl6', doOnIOS: false);
_getWxMsg();
}
//获取开放标签信息
_getWxMsg() async {
String wxMsg = await getExtMsg();
if(wxMsg !=null){
Map<String, dynamic> dataMap;
if(wxMsg.contains('extmsg=')){
String data = wxMsg.split("extmsg=")[1];
dataMap = json.decode(data);
}else{
dataMap = json.decode(wxMsg);
}
var cateId = dataMap['cateId'];
var articleId = dataMap['articleId'];
if(cateId == 34 || cateId == '34'){
if(mounted){
//获取到需要的信息后跳转详情
NavigatorUtil.push(PromotionPostDetail(id: '$articleId'));
}
}
}
}
//调用==============
void initState() {
_initFluwx();
}
void didChangeAppLifecycleState(AppLifecycleState state) {
// TODO: implement didChangeAppLifecycleState
super.didChangeAppLifecycleState(state);
switch(state){
case AppLifecycleState.inactive:
print('======inactive');
break;
case AppLifecycleState.resumed:
print('======resumed');
_getWxMsg();
break;
case AppLifecycleState.paused:
print('======paused');
break;
case AppLifecycleState.detached:
print('======detached');
break;
}
}
3.使用fluwx拉起flutter白屏问题
在app的AndroidMainfest.xml中添加
在这里插入代码片
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jarvan.fluwx_example">
//这个=======(缺少这个导致白屏)
<queries>
<intent>
<action android:name="${applicationId}.FlutterActivity" />
</intent>
</queries>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="fluwx_example">
//这个=======
<meta-data
android:name="weChatAppId"
android:value="12345678" />
//这个=======
<meta-data
android:name="handleWeChatRequestByFluwx"
android:value="true" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:exported="true"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//这个=====
<intent-filter>
<action android:name="${applicationId}.FlutterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
//这个=======
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>