The Beginning of everything – simple foreground push

Now we are going to implement a simple aurora foreground push.

The following examples are implemented on Android, because Android is the most troublesome.

Install Jpush SDK

Aurora Push already natively supports the Flutter SDK, which can be installed as pub

dependencies:
  jpush_flutter: x.x.x
Copy the code

configuration

# /android/app/build.gradle android: { .... DefaultConfig {applicationId "replace applicationId"... NDK {// Select the.so library to add for the CPU type. abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a', } manifestPlaceholders = [ ... JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "appkey", // NOTE: JPUSH_CHANNEL: "developer-default", // enter the default value....] } dependencies {the compile 'cn. Jiguang. SDK: jpush: 4.2.8'}}Copy the code

Write a push utility class

The following is implemented using the singleton pattern

// @/lib/utils/JMPush.dart

import 'package:jpush_flutter/jpush_flutter.dart';

class JMPush {

  static final JMPush _shared = JMPush._internal();
  factory JMPush() => _shared;

  JPush jPush;
  JMPush._internal() {
    if (jPush == null) {
      jPush = newJPush(); }}void init () {
    jPush.setup(
      appKey: "xxxx",
      channel: "theChannel",
      production: false,
      debug: true.// Sets whether to print debug logs
    );
    // jPush.addTags(["dev"]); // You can add tags and push them for the development environment
    jPush.addEventHandler(
      // Receive notification callback method.
      onReceiveNotification: (Map<String.dynamic> message) async {
        print("flutter onReceiveNotification: $message");
      },
      // Click the notification callback method.
      onOpenNotification: (Map<String.dynamic> message) async {
        print("flutter onOpenNotification: $message");
      },
      // Receive custom message callback methods.
      onReceiveMessage: (Map<String.dynamic> message) async {
        print("flutter onReceiveMessage: $message"); }); }}Copy the code

Dart register for use

// @/lib/main.dart
import 'package:[your package]/utils/JMPush.dart';

void main(){
  ...
  runApp(
    Entry()
  );

  newJMPush().init(); . }Copy the code

Test push effect

Sign up for aurora account

Then configure your app icon and name and open the test push screen

And then we were done. We pushed a simple message. However, this is far from enough. Under the restrictions of third-party manufacturers, our app cannot be pushed in the background when it is closed. Please don’t worry, please continue to read.

God said to have light – third-party manufacturers match – Xiaomi

Above, we have realized simple foreground push, but after we close the program, we can’t continue to push. Now, we connect with Xiaomi push based on aurora.

Xiaomi Open Platform

By default, everyone already has a Xiaomi developer account. We open the push on the Xiaomi open platform. At this time, we have AppID and AppKey

Connect to xiaomi SDK

We continue to modify the original basis

# android/app/build.gradle ... defaultConfig { manifestPlaceholders { ... XIAOMI_APPKEY: "mi-xxxx ", // < span style = "max-width: 100%; clear: both; min-height: 1em; The compile 'cn. Jiguang. SDK. The plugin: xiaomi: 4.0.0' / / the version number corresponding to the latest millet push... }...Copy the code
# android/app/src/main/AndroidManifest.xml
...
<application>.<receiver
    android:name="cn.jpush.android.service.PushReceiver"
    android:enabled="true">
    <intent-filter android:priority="1000">
        <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
        <! --Required Display notification bar -->
        <category android:name="${applicationId}" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.USER_PRESENT" />
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    </intent-filter>
    <! -- Optional -->
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />

        <data android:scheme="package" />
    </intent-filter>
</receiver>.</application>.Copy the code

Both the Android /build.gradle file’s BuildScript and AllProjects repositories will open JCenter (), because we are configured for automatic deployment

Enable aurora third-party configuration

After you open it, you will find that a connection has been established in xiaomi background

At this point we pack up and run to the phone. Xiao Mi Push Register Success xiao MI push register success xiao MI push register success

Then close the app and push the test.

Note that Mi is going to fold unimportant notifications. There is no solution to this, only the user manually set to important notifications.

And then you’re done! This article is not finished yet. Next, I will adapt other vendors’ push, please wait and see.

Huawei adaptation

Registered Developer

By default, you have registered as a Huawei developer and created the application. After registering the application with Huawei developers, the agconnect-services.json file is stored in the /Android/app/ directory

To integrate the SDK

# android/app/build.gradle dependencies { ... / / push huawei certificate add implementation 'cn. Jiguang. SDK. The plugin: huawei: 3.6.8' implementation 'com. Huawei. HMS: push: 4.0.2.300'... } // Huawei push certificate add apply plugin: 'com.huawei.agconnect'Copy the code
# android/build.gradle BuildScript {repositories {Google () jCenter () // Huawei Push certificate add maven {url 'http://developer.huawei.com/repo/' dependencies}} {the classpath 'com. Android. View the build: gradle: 3.5.0' classpath "Org. Jetbrains. Kotlin: kotlin - gradle - plugin: $kotlin_version" / / certificate of huawei's push to add the classpath 'com. Huawei. Agconnect: agcp: 1.2.1.301'} Jcenter} allprojects {repositories {Google () () / / push huawei certificate to add maven {url 'http://developer.huawei.com/repo/'}}}Copy the code

Certificate of binding

Here, bind your application’s certificate *.jks to the application, please ignore the binding

# android/app/build.gradle signingConfigs {release {storeFile file("key/key.jks")// Path storePassword "123456" keyAlias "key" keyPassword "123456" } }Copy the code

The sha256 certificate is bound to the Huawei background

keytool -list -v -keystore xxx.jks

Fill in the corresponding manufacturer’s APP key and secret key of aurora, and you’re done

OPPO

Here is simple, because the most troublesome millet and Huawei are done, the following do.

Jcenter is automatically integrated by default and we already added Center above

buildscript {
    repositories {
        jcenter()
    }
        ......
}

allprojets {
    repositories {
        jcenter()
    }
}
Copy the code

Add oppo dependencies

# / android/app/build. Gradle dependencies {the compile 'cn. Jiguang. SDK. The plugin: oppo: 4.0.5'} manifestPlaceholders = [/ / Set the variable OPPO_APPKEY in manifest.xml to "OP- APPKEY of OPPO for your application ", // OPPO platform registered APPKEY OPPO_APPID: OPPO_APPSECRET: "OPPO - APPSECRET of OPPO "// APPSECRET of OPPO]Copy the code

VIVO

Jcenter is still automatically integrated by default. We’ve already added Center above

buildscript {
    repositories {
        jcenter()
    }
        ......
}

allprojets {
    repositories {
        jcenter()
    }
}
Copy the code

Add VIVO dependencies

# / android/app/build. Gradle dependencies {the compile 'cn. Jiguang. SDK. The plugin: vivo: 4.0.5'} manifestPlaceholders = [/ / Set the variable VIVO_APPKEY in manifest.xml to "the APPKEY of VIVO for your application ", // VIVO_APPID for VIVO platform registration: "The APPID of VIVO corresponding to your application ", // the APPID registered by VIVO platform]Copy the code