Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing JPush Push Notifications for Google Play Version in Flutter

Tech 1

Basic JPush Integration

  1. Add the depandency in pubspec.yaml:
dependencies:
  jpush_flutter: ^2.4.2
  1. Create a JPush utility class:
class PushNotificationManager {
  static initialize() {
    JPush().addEventHandler(
      onReceiveNotification: (Map message) async {
        print('Notification received: $message');
      },
      onOpenNotification: (Map message) async {
        print('Notification opened: $message');
        resetBadge();
      },
      onNotifyMessageUnShow: (Map message) async {
        resetBadge();
      },
    );

    JPush().applyPushAuthority(
      NotificationSettingsIOS(sound: true, alert: true, badge: true)
    );

    JPush().setup(
      appKey: 'your_app_key',
      channel: 'developer-default',
      production: false,
      debug: true
    );
  }

  static updateTags(List<String> tags) {
    JPush().setTags(tags);
  }

  static setUserAlias(String alias) {
    JPush().setAlias(alias);
  }

  static removeAlias() {
    JPush().deleteAlias();
  }

  static clearTags() {
    JPush().cleanTags();
  }

  static resetBadge([int count = 0]) {
    JPush().setBadge(count);
  }
}
  1. Configure build.gradle:
android {
    defaultConfig {
        manifestPlaceholders = [
            JPUSH_PKGNAME: "your.package.name",
            JPUSH_APPKEY: "your_app_key",
            JPUSH_CHANNEL: "developer-default",
            
            // Manufacturer-specific keys
            XIAOMI_APPID: "",
            XIAOMI_APPKEY: "",
            OPPO_APPID: "",
            OPPO_APPKEY: "",
            OPPO_APPSECRET: "",
            VIVO_APPID: "",
            VIVO_APPKEY: ""
        ]
    }
}

Google Play Version Modifications

  1. Dwonload the Google Play version of JPush SDK matching your plugin version
  2. Replace the SDK files in jpush_flutter/android/libs/
  3. Modify the plugin's build.gradle:
dependencies {
    implementation 'cn.jiguang.sdk:jpush:4.9.0'
    compile files('libs/jcore-android-4.1.0-google_play.jar')
}

For JPush 5.0+ versions, use:

implementation('cn.jiguang.sdk:jpush:5.4.0') {
    exclude module: 'jcore'
}
compile files('libs/jcore-android-4.7.0-google_play.jar')

This configurasion resolves duplicate class conflicts while maintaining push notification functionality for Google Play distribution.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.