[toc]

Flutter integration aurora all stomp pits

Common Integration (non-paid version, aurora channel)

Common integration is not difficult, just go to the aurora plugin:

Import the corresponding package

Add-in package address

Direct YAML dependencies, get a wave

Report RegisterID

  _initRegisterID(phoneModel) {
    jPush.getRegistrationID().then((rid) {
      if(rid ! =null && rid.isNotEmpty == true) {
        print('---->rid:${rid}');
        var params = {};
        params["registrationId"] = rid;
        params["phoneModel"] = Platform.isAndroid ? 'Android' : 'IOS'; LoginRepository.reportRegisterId(params); }}); }Copy the code

You can also use other methods, more commonly aliases, to push.

Handle the corresponding callback

  jPush.applyPushAuthority(
        NotificationSettingsIOS(sound: true, alert: true, badge: true));
Copy the code
    try {
      jPush.addEventHandler(
          onReceiveNotification: (Map<String.dynamic> message) async {
        print('---->onReceiveNotification:$message');
      }, onOpenNotification: (Map<String.dynamic> message) async {
        print('1111----> Receive push :$message');
       /// do some things
      });
    } on Exception {
      print("----> Failed to obtain platform version");
    }
Copy the code

Some of the problems I encountered

This is basically integrated, but there are some problems:

  1. Ios clicks do not trigger events
  2. Ios failed to get ExtrAs after killing the process
  3. Welcome to issues for more questions

And the aurora on pub doesn’t seem to be up to date, depending on it

  jpush_flutter:
    git:
      url: git://github.com/jpush/jpush-flutter-plugin.git
      ref: master
Copy the code

Problem 1 has been solved.

But other problems remain, and!!

Paid vendor channel integration

Important things to say three times:

Plugin is the basic free version, there is no paid version !!!!

Plugin is the basic free version, there is no paid version !!!!

Plugin is the basic free version, there is no paid version !!!!

The paid version needs to implement the plugin itself,

Based on integration

Basic vendor integration requires Coder to manually integrate various vendor SDKS in its Android project:

// Xiaomi Aurora push SDK
    implementation 'cn. Jiguang. SDK. The plugin: xiaomi: 3.6.8'
// Huawei push
    implementation 'com. Huawei. HMS: push: 4.0.2.300'
    implementation 'cn. Jiguang. SDK. The plugin: huawei: 3.6.8'
// Meizu push
    implementation 'cn. Jiguang. SDK. The plugin: meizu: 3.6.8'
// vivo
    implementation 'cn. Jiguang. SDK. The plugin: vivo: 3.6.8'
// oppo
    implementation 'cn. Jiguang. SDK. The plugin: oppo: 3.6.8'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
Copy the code

Documentation for basic integration can be found in this section:

Integrated documentation for each vendor

Plug-in integrated

Because it is through the manufacturer’s channel, most of the push messages will not go through the callback after integration. Except meizu, which has no layout, it integrates SDK and goes through the common channel (dog head).

Aurora expects developers to implement their own plug-in, receive push messages on the native side, and bridge them to the Futter side for consumption:

  1. Aurora sends push messages
  2. The relay AC is pulled up and gets the corresponding push field
  3. Jump to mainActivity and pass the data, mainActivity takes the data and passes it to the flutter end via MethodChannel
  4. The flutter end is processed for consumption.

OpenClickActivity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
// mTextView = new TextView(this);
// setContentView(mTextView);
// handleOpenClick();
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Intent intent = new Intent(this, MainActivity.class);
        intent.setData(getIntent().getData());
        if(getIntent().getExtras() ! =null) {
            intent.putExtras(getIntent().getExtras());
        }
        startActivity(intent);
        finish();
    }
Copy the code

MainActivity

private void handleOpenClick(MethodChannel channel, Intent intent) {

        String data = null;
        // Obtain the jpush information attached to Huawei platform
        if(intent.getData() ! =null) {
                data = intent.getData().toString();
        }

        // Obtain the Jpush information attached to FCM, OPPO, Vivo, Asus and Xiaomi platforms
        if(TextUtils.isEmpty(data) && intent.getExtras() ! =null){
            data = intent.getExtras().getString("JMessageExtra");
        }

        if (TextUtils.isEmpty(data)) return;
        try {
            JSONObject jsonObject = new JSONObject(data);
            String msgId = jsonObject.optString(KEY_MSGID);
            byte whichPushSDK = (byte) jsonObject.optInt(KEY_WHICH_PUSH_SDK);
            String title = jsonObject.optString(KEY_TITLE);
            String content = jsonObject.optString(KEY_CONTENT);
            String extras = jsonObject.optString(KEY_EXTRAS);

            final Handler mHandler = new Handler();
            Runnable r = () -> {
                //do something
                Map<String.String> map = new HashMap<>();
                map.put("msgId", msgId);
                map.put("whichPushSDK", whichPushSDK + "");
                map.put("title", title);
                map.put("content", content);
                map.put("extras", extras);
// Toast.makeText(MainActivity.this, map.toString(), Toast.LENGTH_SHORT).show();
                channel.invokeMethod("notifyclick", map);
            };
            // call from main thread:
            mHandler.postDelayed(r, 100);// The delay is 100 milliseconds
        } catch (JSONException e) {
            Log.w(TAG, "parse notification error"); }}Copy the code

Flutter

 Future<Null> _handleMethod(MethodCall call) async {
    print("_handleMethod: ${call.method}");

    switch (call.method) {
      case "notifyclick":
        return notifyclick(call.arguments.cast<String.dynamic> ());default:
        throw new UnsupportedError("Unrecognized Event");
    }
  }

  Future<dynamic> notifyclick(Map<String.dynamic> message) async {
    print('1111----> Receive push :$message');
    String pushType;
    String afterSalesId;
    String appMessageId;
    String extra=message["extras"];
    print(extra); JpushModel jpushModel=JpushModel.fromJson(jsonDecode(extra)); pushType=jpushModel? .pushType; afterSalesId=jpushModel? .afterSalesId; appMessageId=jpushModel? .appMessageId;if (pushType == "stationMessage") {
      print('----------appMessageId= $appMessageId');
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => MessageDetailPage(
                    messageCellList:
                        MessageCellList(appMessageId: int.parse(appMessageId)),
                  )));
    } else {
// if (Platform.isAndroid) {
        String _jumpUrl =
            JPushConf.getJumpUrlByJpush(pushType, afterSalesId: afterSalesId);
        WechatUtils().launchMiniPro(_jumpUrl);
// } else {
// WechatUtils().launchMiniPro('${WechatMiniUrl.choose_url}');
/ /}
    }

Copy the code

AndroidManifest

   <activity android:name=".OpenClickActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:exported="true">
            <intent-filter>
                <data android:path="/ypath" android:host="yhost" android:scheme="yscheme"></data>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </activity>

        <! -- 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" />
Copy the code

Points to be aware of

  1. If the ac configuration is wrong, click the notification to pull up the app, but you will not get extras. This is very nasty. Do not misconfigure the ac configuration in AndroidManifest, otherwise it will be easy to pull up and get no data.

  2. Need background cooperation

    Previous versions of the server SDK did not provide the uri_activity configuration. If you find this field missing, update the version: