示例#1
0
 public boolean sendMessage(Message message, boolean encrypt) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   String perfData = MessageProfiling.getPrefString();
   if (!TextUtils.isEmpty(perfData)) {
     CommonPacketExtension perfExt =
         new CommonPacketExtension("pf", null, (String[]) null, (String[]) null);
     CommonPacketExtension sentPerfExt =
         new CommonPacketExtension(
             PushServiceConstants.SEND_MSG_EVENT_TYPE_SENT,
             null,
             (String[]) null,
             (String[]) null);
     sentPerfExt.setText(perfData);
     perfExt.appendChild(sentPerfExt);
     message.addExtension(perfExt);
   }
   Bundle messageBundle = message.toBundle();
   if (messageBundle == null) {
     return false;
   }
   MyLog.v("SEND:" + message.toXML());
   intent.setAction(PushConstants.ACTION_SEND_MESSAGE);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKET, messageBundle);
   intent.putExtra(PushConstants.EXTRA_ENCYPT, encrypt);
   this.mContext.startService(intent);
   return true;
 }
示例#2
0
 public boolean batchSendMessage(Message[] messages, boolean encrypt) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   Bundle[] messageBundles = new Bundle[messages.length];
   for (int i = 0; i < messages.length; i++) {
     String perfData = MessageProfiling.getPrefString();
     if (!TextUtils.isEmpty(perfData)) {
       CommonPacketExtension perfExt =
           new CommonPacketExtension("pf", null, (String[]) null, (String[]) null);
       CommonPacketExtension sentPerfExt =
           new CommonPacketExtension(
               PushServiceConstants.SEND_MSG_EVENT_TYPE_SENT,
               null,
               (String[]) null,
               (String[]) null);
       sentPerfExt.setText(perfData);
       perfExt.appendChild(sentPerfExt);
       messages[i].addExtension(perfExt);
     }
     MyLog.v("SEND:" + messages[i].toXML());
     messageBundles[i] = messages[i].toBundle();
   }
   if (messageBundles.length <= 0) {
     return false;
   }
   intent.setAction(PushConstants.ACTION_BATCH_SEND_MESSAGE);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKETS, messageBundles);
   intent.putExtra(PushConstants.EXTRA_ENCYPT, encrypt);
   this.mContext.startService(intent);
   return true;
 }