flutter使用百川SDK

开通权限

image.png

百川官网下载安全图片

image.png

分为ios版本和android版本,
ios BundleID直接写你flutter app的BundleID,我的是com.tangxxx.app
android需要你用keytools生成带签名的apk,然后上传。详情请看https://www.jianshu.com/p/398d41128b02

android添加安全图片

复制安全图片到android/app/src/main/res/drawable/yw_1222.jpg

ios添加安全图片

将yw_1222.jpg改名为yw_1222_baichuan.jpg复制到项目ios目录下,

用xcode添加资源文件,用xcode打开ios下的Runner


image.png

选择add other,选取ios目录下的yw_1222_baichuan.jpg,确定。

引入百川SDK

打开ios/podfile,在最前面添加

source 'http://repo.baichuan-ios.taobao.com/baichuanSDK/AliBCSpecs.git'
image.png

使用flutter_alibc这个库

flutter_alibc:https://pub.dev/packages/flutter_alibc
1、在pubspec.yaml引用。

2、打开android/app/src/main/AndroidManifest.xml,在application标签中加入子标签

<activity android:name="com.wxwx.flutter_alibc.web.WebViewActivity"></activity>

如果flutter build apk 的时候提示建议加入tools:replace="android:label"
就打开AndroidManifest.xml,
<manifest标签加入属性xmlns:tools="http://schemas.android.com/tools"
<application标签加入属性tools:replace="android:label"

完整AndroidManifest.xml文件如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.tangmiao.app">
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         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. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="糖喵"
        android:icon="@mipmap/ic_launcher"
        android:networkSecurityConfig="@xml/network_security_config"
        tools:replace="android:label"
        >
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.wxwx.flutter_alibc.web.WebViewActivity"></activity>
    </application>
</manifest>