MixPush Hybrid Push SDK

repository·master·Indexed 22 days ago

https://github.com/taoweiji/mixpush

A hybrid push SDK that integrates multiple manufacturer-specific push channels—including Xiaomi, Huawei, OPPO, VIVO, Meizu, and Apple APNs—into a single unified interface. It is designed to achieve high delivery rates (90%+) by utilizing system-level channels, ensuring notifications are received even when the app is killed. The SDK includes Android client libraries and a Java-based server-side sender (mixpush-sender) for backend implementation.

Tokens
5.1K
Snippets
6
Records
20
Agent score
79%

What's inside MixPush

  1. Overview of MixPush Hybrid Push SDK

    master

    MixPush is a hybrid push SDK that integrates six major manufacturer push platforms (Xiaomi, Huawei, OPPO, VIVO, Meizu, and Apple APNs) to ensure high delivery rates (90%+) even when the app is killed. It intelligently selects the best available manufacturer channel for the device, sharing system channels to avoid the need for the app to run continuously in the background.

    Key Features:

    • High Delivery Rate: Uses system-level manufacturer channels to reach users even if the app is killed.
    • Intelligent Selection: Automatically chooses the most appropriate push platform based on device support.
    • Low Integration Cost: Provides a unified interface for multiple manufacturers.
    • Server-side Support: Includes Java code for easy backend implementation.

    Important Note: This SDK does not support commercial third-party push platforms to avoid unauthorized advertising and user interference.

  2. Best practices for server-side push delivery

    master

    To ensure high delivery rates and avoid resource waste, follow these guidelines:

    1. RegId Management: Request the client to register/update its RegId via API every time the app opens. Record this timestamp on the server.
    2. Avoid Stale Users: Do not attempt to push to users who haven't opened the app for more than 3 months (or 6 months for APNs) to reduce pressure and waste resources.
    3. Global Push Limitations: Huawei and Apple (APNs) do not support global push. You must query all RegIds from your database and perform group/batch pushes instead.
    4. Operational vs. System Messages: Use 'System Messages' (via specific channel IDs) for high-frequency/critical alerts like IM or order updates. Standard 'Operational' channels have daily limits imposed by manufacturers (Xiaomi, OPPO, VIVO).
  3. Compare supported push platforms and capabilities

    master

    MixPush supports various features across different manufacturers. Use this table to plan your push strategy:

    Push PlatformPassthrough (透传)Global PushAlias/TagSupport Notes
    XiaomiSupportedSupportedSupportedAll Android; system-level on Xiaomi devices
    HuaweiSupportedNot SupportedNot SupportedHuawei devices (EMUI 4.0/4.1, 5.0+)
    OPPONot SupportedSupportedSupportedOPPO/OnePlus (ColorOS 3.1+)
    VIVONot SupportedSupportedSupportedVIVO (Android 9.0+)
    MeizuNot SupportedSupportedSupportedMeizu (Flyme)
    APNsNot SupportedNot SupportedNot SupportedApple devices
    Xiaomi APNsNot SupportedSupportedSupportedApple devices (reduces server pressure)

    Recommendations:

    1. Fallback: If a manufacturer push is not supported, use Xiaomi push.
    2. Unified ID: Since Huawei does not support aliases/tags, it is recommended to use regId for all pushes.
    3. Passthrough: If you require passthrough support, use Xiaomi push as the primary method.
    4. Global Push: Since Huawei and APNs do not support global push, target users who have opened the app in the last 3 months to avoid expired tokens.
  4. Configure Android project build files

    master

    To use MixPush, you must first configure your Gradle files to include the Huawei AgConnect plugin and the necessary repositories.

    1. Root build.gradle configuration: Add mavenCentral() and the Huawei repository.

    2. App build.gradle configuration: Apply the Huawei AgConnect plugin and define manifestPlaceholders for the various manufacturer credentials.

    // Root build.gradle
    buildscript {
        repositories {
          	...
            mavenCentral()
            maven { url 'http://developer.huawei.com/repo/' }
        }
        dependencies {
            ...
            classpath 'com.huawei.agconnect:agcp:1.6.0.300'
        }
    }
    allprojects {
        repositories {
            ...
            mavenCentral()
            jcenter()
            maven { url 'http://developer.huawei.com/repo/' }
        }
    }
    
    // App build.gradle
    apply plugin: 'com.huawei.agconnect'
    android {
        compileSdkVersion 31
        defaultConfig {
            ...
            manifestPlaceholders["VIVO_APP_ID"] = "<VIVO_APP_ID>"
            manifestPlaceholders["VIVO_APP_KEY"] = "<VIVO_APP_KEY>"
            manifestPlaceholders["MI_APP_ID"] = "<MI_APP_ID>"
            manifestPlaceholders["MI_APP_KEY"] = "<MI_APP_KEY>"
            manifestPlaceholders["OPPO_APP_KEY"] = "<OPPO_APP_KEY>"
            manifestPlaceholders["OPPO_APP_SECRET"] = "<OPPO_APP_SECRET>"
            manifestPlaceholders["MEIZU_APP_ID"] = "<MEIZU_APP_ID>"
            manifestPlaceholders["MEIZU_APP_KEY"] = "<MEIZU_APP_KEY>"
        }
    }
    dependencies {
        def mixpush_version = '2.4.0'
        implementation "io.github.mixpush:mixpush-core:$mixpush_version" // Core
        implementation "io.github.mixpush:mixpush-mi:$mixpush_version" // Xiaomi
        implementation "io.github.mixpush:mixpush-meizu:$mixpush_version"  // Meizu
        implementation "io.github.mixpush:mixpush-huawei:$mixpush_version"  // Huawei
        implementation "io.github.mixpush:mixpush-oppo:$mixpush_version"  // OPPO
        implementation "io.github.mixpush:mixpush-vivo:$mixpush_version"  // VIVO
    }
  5. Configure Huawei Push requirements

    master

    Huawei push requires three specific steps to avoid errors:

    1. Download agconnect-services.json from the Huawei official documentation and place it in your app directory.
    2. Configure your SHA256 certificate fingerprint in the Huawei console to avoid Error 6003.
    3. Configure your fingerprint certificate to avoid Error 907135702.
  6. Add MixPush Sender dependency to Java project

    master

    To use the MixPush server-side capabilities, add the mixpush-sender dependency to your Maven pom.xml file.

    <dependencies>
        <dependency>
            <groupId>io.github.mixpush</groupId>
            <artifactId>mixpush-sender</artifactId>
            <version>2.3.9</version>
        </dependency>
    </dependencies>
  7. Initialize MixPush in Android Application

    master

    To use MixPush, you need to implement a MixPushReceiver to handle registration success and notification clicks, then initialize the SDK in your Application class.

    1. Implement MixPushReceiver: Override onRegisterSucceed to upload the regId and platform info to your server. Override onNotificationMessageClicked to handle user interaction with notifications.

    2. Initialize in Application: Set the receiver and call register(this). By default, it initializes 5 platforms (Xiaomi, Huawei, Meizu, OPPO, VIVO) using Xiaomi as the recommended default.

    3. Retrieve regId: Use MixPushClient.getInstance().getRegisterId() to get the unique registration ID for the current device and send it to your backend.

    // 1. Define the Receiver
    public class MyPushReceiver extends MixPushReceiver {
        @Override
        public void onRegisterSucceed(Context context, MixPushPlatform mixPushPlatform) {
            // TODO: Upload regId and platform info to your server
        }
    
        @Override
        public void onNotificationMessageClicked(Context context, MixPushMessage message) {
          // TODO: Handle notification click (e.g., open a specific page)
        }
    }
    
    // 2. Initialize in Application
    // MixPush.getInstance().setLogger(new PushLogger(){});
    MixPush.getInstance().setPushReceiver(new MyPushReceiver());
    MixPush.getInstance().register(this);
    
    // 3. Get regId (Call this in your Activity's onCreate, e.g., Home Activity)
    MixPushClient.getInstance().getRegisterId(this, new GetRegisterIdCallback() {
        public void callback(MixPushPlatform platform) {
            if (platform != null) {
                Log.e("GetRegisterIdCallback", platform.toString());
                // TODO: Upload regId to your server
            }
        }
    });
  8. Send a notification message with MixPush

    master

    To send a message, construct a MixPushMessage using its builder, define a MixPushTarget (e.g., single device or group), and call sender.sendNotificationMessage(message, target).

    Note: For OPPO, you must register a channel in the OPPO console first and provide the oppoPushChannelId in the message configuration.

    MixPushMessageConfig activitiesMessageConfig = new MixPushMessageConfig.Builder()
            // OPPO 必须在“通道配置 → 新建通道”模块中登记通道,再在发送消息时选择
            .oppoPushChannelId("activities")
            .build();
    
    MixPushMessage message = new MixPushMessage.Builder()
            .title("这里是标题")
            .description("这里是副标题")
            .payload("{\"url\":\"http://github.com/taoweiji\"}")
            .config(activitiesMessageConfig)
            .build();
    
    MixPushTarget target = MixPushTarget.single("mi","xxxx");
    sender.sendNotificationMessage(message,target);
  9. Initialize MixPushSender on the server

    master

    Use MixPushSender.Builder to configure credentials for all supported push platforms (Xiaomi, Meizu, Huawei, OPPO, VIVO, and APNs). You can also enable test mode using .test(true).

    MixPushSender sender = new MixPushSender.Builder()
            .packageName("<packageName>")
            .mi("<appSecretKey>", false)
            .meizu("<appId>", "<appSecretKey>")
            .huawei("<appId>", "<appSecretKey>")
            .oppo("<appKey>", "<masterSecret>")
            .vivo("<appId>", "<appKey>", "<appSecretKey>")
            .miAPNs("<appSecretKey>")
            .test(true)
            .build();
  10. Configure MixPushMessage

    master

    The MixPushMessage.Builder defines the content and behavior of the notification:

    MethodDescription
    titleNotification title. Required if passThrough is false
    descriptionNotification subtitle. Required if passThrough is false
    payloadThe message body. Must be in JSON format
    passThroughfalse: Standard notification; true: Silent/Data message (透传)
    messageIdOptional. Used for tracking results
    configRequired. An instance of MixPushMessageConfig
  11. Configure ProGuard rules for MixPush

    master

    Add the following rules to your ProGuard configuration to prevent the SDK and its manufacturer-specific providers from being obfuscated or stripped during the build process.

    # MixPush
    -keep class com.mixpush.mi.MiPushProvider {*;}
    -keep class com.mixpush.meizu.MeizuPushProvider {*;}
    -keep class com.mixpush.huawei.HuaweiPushProvider {*;}
    -keep class com.mixpush.oppo.OppoPushProvider {*;}
    -keep class com.mixpush.vivo.VivoPushProvider {*;}
     
    # 华为推送
    -ignorewarnings
    -keepattributes *Annotation*
    -keepattributes Exceptions
    -keepattributes InnerClasses
    -keepattributes Signature
    -keepattributes SourceFile,LineNumberTable
    -keep class com.huawei.hianalytics.**{*;}
    -keep class com.huawei.updatesdk.**{*;}
    -keep class com.huawei.hms.**{*;}
    
    # 小米推送
    -keep class com.xiaomi.**{*;}
    
    # OPPO
    -keep public class * extends android.app.Service
    -keep class com.heytap.msp.** { *;}
    
    # VIVO
    -dontwarn com.vivo.push.** 
    -keep class com.vivo.push.**{*; }
    -keep class com.vivo.vms.**{*; }
    
    # 魅族
    -keep class com.meizu.**{*;}