SMSReceivedEvent.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:LibreTasks 作者:
/**
 * Examines the Protocol Description Unit (PDU) data in the text message intent to reconstruct the
 * phone number and text message data. Caches the information in global variables in case they are
 * needed again.<br>
 * TODO(londinop): Further test this method with texts longer than 160 characters, there may be a
 * bug in the emulator
 */
private void getMessageData() {

  // TODO(londinop): Add text message data retrieval code and write a test for it
  Bundle bundle = intent.getExtras();
  Object[] pdusObj = (Object[]) bundle.get("pdus");

  // Create an array of messages out of the PDU byte stream
  SmsMessage[] messages = new SmsMessage[pdusObj.length];
  for (int i = 0; i < pdusObj.length; i++) {
    messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
  }
  // Get the sender phone number from the first message
  // TODO(londinop): Can there be multiple originating addresses in a single intent?
  phoneNumber = messages[0].getOriginatingAddress();

  // Concatenate all message texts into a single message (for texts longer than 160 characters)
  StringBuilder sb = new StringBuilder();
  for (SmsMessage currentMessage : messages) {
    sb.append(currentMessage.getDisplayMessageBody());
  }
  messageText = sb.toString();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号