已成功用極光通道收到推送,為了能在app被殺的情況下繼續收推送,需要接入廠家通道,接華為的時候踩了一頓坑
新建Flutter項目,使用官方jpush_flutter包,版本2.1.4
第一步:生成jks簽名文件
見 Flutter中生成Android的jks簽名文件並使用
獲取SHA256簽名指紋 
第二步:在華為AGC上對應的項目下配置簽名信息並下載agconnect-services.json
指紋填完后記得點勾保存,再下載文件,很重要,不然拿不到token
第三步 在極光后台配置華為通道的app資料

第四步 修改項目gradle,加入華為庫maven
第五步 修改模塊gradle
加入插件代碼
apply plugin: 'com.huawei.agconnect'
配置極光參數,接入華為通道minSdkVersion要17以上
defaultConfig {
applicationId "com.xxx.jpush.demo"
ndk {
//選擇要添加的對應 cpu 類型的 .so 庫。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a'
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "xxxxxxxxxxxxxxxx", //JPush 上注冊的包名對應的 Appkey.
JPUSH_CHANNEL : "developer-default", //暫時填寫默認值即可.
]
minSdkVersion 17
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
加入華為依賴包
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// // 接入華為廠商
implementation 'com.huawei.hms:push:5.3.0.301'
implementation 'cn.jiguang.sdk.plugin:huawei:4.0.9'// 極光廠商插件版本與接入 JPush 版本保持一致,下同
}
jpush_flutter我用的2.1.4,翻源碼SDK版本是 cn.jiguang.sdk:jpush:4.0.9
修改AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jpush_demo"
xmlns:tools="http://schemas.android.com/tools">
<permission android:name="${applicationId}.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application android:name="io.flutter.app.FlutterApplication"
android:label="jpush_demo"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
tools:replace="android:label">
<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:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="cn.jpush.android.service.DaemonService"
android:enabled="true"
android:exported="true">
<intent-filter >
<action android:name="cn.jpush.android.intent.DaemonService" />
<category android:name="${applicationId}"/>
</intent-filter>
</service>
<service android:name=".services.HmsService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
根節點加入命名空間屬性 xmlns:tools="http://schemas.android.com/tools" application節點加入屬性 tools:replace="android:label"
加入兩個Service
運行程序,成功連接華為日志出現以下文字
成功后在極光后台檢測集成,就會出現華為通道已集成

測試下發時選擇廠商優先
