【flutter h5微信开放标签拉起app】

本文介绍了如何在Flutter应用中引入fluwx库处理微信H5页面的分享事件,通过获取开放标签信息来决定是否跳转到详细内容页,并解决使用fluwx时可能出现的Android白屏问题,涉及AndroidManifest.xml配置。
摘要由CSDN通过智能技术生成

分享到微信的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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值