English | 中文
This is a demo on how to use Huawei Push.
- Add Huawei Push sdk
flutter pub get huawei_push
-
Add
agconnect-services.json
file inandroid/app/
(Get agconnect-services.json). -
Add Huawei's AppId in
android/app/src/main/AndroidManifest.xml
<application>
...
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="Your huawei appid">
</meta-data>
...
</application>
- Add
xxx.jks
signature file inandroid/app/
directory (Configure signature
), and add signingConfigs
information to android/app/build.gradle
, and configure obfuscation file (Configure obfuscation file).
android{
...
signingConfigs {
config {
keyAlias 'xxxx'
keyPassword 'xxxx'
storeFile file('huawei_push_flutter.jks')
storePassword 'xxxx'
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.debug
}
}
...
}
- Upload the certificate fingerprint to Huawei Push backend (Get certificate fingerprint).
-
Integrate im sdk.
-
Upload Huawei Push configuration to Easemob backend Upload certificate to im backend.
-
Need to start HWPush during initialization.
void main() {
WidgetsFlutterBinding.ensureInitialized();
final options = ChatOptions(appKey: "Your Appkey");
// Enable push
options.enableHWPush();
EMClient.getInstance.init(options).then((value) => runApp(const MyApp()));
}
- Get Huawei Push token, and pass the Huawei Push token to im sdk after im login
Push.getTokenStream.listen(
(event) async {
_token = event;
try {
await ChatClient.getInstance.pushManager.updateHMSPushToken(_token);
} catch (e) {
debugPrint('bind token error: $e');
}
showResult('TokenEvent', _token);
},
onError: (e) {
debugPrint('get token error: $e');
},
);