MobPush Android push message data analysis recommendation implementation

Time:2022-11-18

The main types of MobPush push message analysis needs are divided into TCP messages and manufacturer messages. TCP messages: MobPush application online defaults through the TCP channel created by MobTech itself, called TCP messages. Manufacturer’s message: The push of the application end process status needs to go through the manufacturer’s channel (Huami OV charm channel). Therefore, push message parsing is mainly processed for these two types of messages. The following two analysis methods are recommended. For more operation details, please refer toOfficial website document

Unified analysis through intent (recommended)

The push message can be processed by parsing the intent in a unified way. It should be noted that due to the Android system problem, the startup mode of the message landing page Activity needs to be SingleTask or SingleTop. Otherwise, the onCreate and OnNewIntent of the landing page may not be triggered, and the parsing of the manufacturer’s message fails, and a transparent Activity can be used. As a landing page, other logic such as jumping is performed according to parameters. Parsing example:

protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
     // Through the analysis method provided by Mob, according to the analysis parameters, it can be judged whether the message is a manufacturer message or a tcp message, which needs to be processed separately. For examples of printing parameters, refer to 3 and 4.
     JSONArray jsonA = MobPushUtils.parseMainPluginPushIntent(getIntent());
     System.out.println("-------------jsonSchemejsonA print view: "+jsonA )
     JSONArray var =  MobPushUtils.parseSchemePluginPushIntent(getIntent());
     System.out.println("-------------jsonSchemevar print view: "+var)
}
protected void onNewIntent(Intent intent) {

      // Through the analysis method provided by MobTech, according to the analysis parameters, it can be judged whether the message is a manufacturer message or a tcp message, which needs to be processed separately. For printing examples, refer to 3 and 4.
      super.onNewIntent(intent);
      setIntent(intent);
      JSONArray jsonA = MobPushUtils.parseMainPluginPushIntent(getIntent());
      System.out.println("-------------jsonSchemejsonA print view: "+jsonA )
      JSONArray var =  MobPushUtils.parseSchemePluginPushIntent(getIntent());
      System.out.println("-------------jsonSchemevar print view: "+var)
}

Distinguished processing: TCP messages are processed through MobTech callbacks, and vendor messages are parsed and processed with Intents

MobPush TCP messages can be processed through callbacks as follows:

MobPushReceiver mobPushReceiver = new MobPushReceiver() {

        @Override
        public void onCustomMessageReceive(Context context, MobPushCustomMessage message) {
            //Received a custom message (transparent message)
            message.getMessageId();//Get task ID
            message.getContent();//Get push content
        }

        @Override
        public void onNotifyMessageReceive(Context context, MobPushNotifyMessage message) {
            //received notification message
            message.getMobNotifyId();//Get message ID
            message.getMessageId();//Get task ID
            message.getTitle();//Get push title
            message.getContent();//Get push content
        }

        @Override
        public void onNotifyMessageOpenedReceive(Context context, MobPushNotifyMessage message) {
            //notify clicked event
            message.getMobNotifyId();//Get message ID
            message.getMessageId();//Get task ID
            message.getTitle();//Get push title
            message.getContent();//Get push content
        }

        @Override
        public void onTagsCallback(Context context, String[] tags, int operation, int errorCode) {
            // label operation callback
            //tags: the tag that RegistrationId has added
            //operation: 0 get label 1 set label 2 delete label
            //errorCode: 0 operation succeeds, non-0 operation fails
        }

        @Override
        public void onAliasCallback(Context context, String alias, int operation, int errorCode) {
            //alias operation callback
            //alias: Alias ​​corresponding to RegistrationId
            //operation: 0 get alias 1 set alias 2 delete alias
            //errorCode: 0 operation succeeds, non-0 operation fails
        }

    };

Vendor message must resolve intent through onCreate or onNewIntent

protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        // Through the analysis method provided by Mob, according to the analysis parameters, it can be judged whether the message is a manufacturer message or a tcp message, which needs to be processed separately. For printing examples, refer to 3.
        JSONArray jsonA = MobPushUtils.parseMainPluginPushIntent(getIntent());
        System.out.println("-------------jsonSchemejsonA print view: "+jsonA )
        JSONArray var =  MobPushUtils.parseSchemePluginPushIntent(getIntent());
        System.out.println("-------------jsonSchemevar print view: "+var)
}

Example of TCP message parsing parameters

[
  {
   "from_tcp":true
  },
  {
   "msg":"MobPushNotifyMessage{style=0, title='111', content='111', styleContent='null', inboxStyleContent=null, extrasMap={pushData={\"iskey\":\"https://www.mob.com\"}, iskey=https://www.mob.com, channel=mobpush, id=4bp4tw9talcex9jf28}, messageId='4bp4tw9talcex9jf28', timestamp=1647939368936, voice=true, shake=true, light=false, channel=0, notifySound='null', dropType=0, dropId='null', mobNotifyId='1257662669', offlineFlag=0, isGuardMsg=false, icon='null', image='null', androidBadgeType=0, androidBadge=0, androidChannelId='MobPush', importance='3', notificationChannelName=' Message notification ', isLockscreenVisible='false', allowBubbles='false'}"
  },
  {
   "channel":"mobpush"
  }
]

Manufacturer parsing parameter example, can directly parse additional parameters

[
  {
   "from_tcp":“false”
  },
  {
   "id":"4bp4tw9taldddxxreo"
  },
  {
   "channel":"huawei"
   },
  {
   "iskey":"https://www.mob.com"
  }
]