Receive and concatenation SMS more than 160 characters in android

后端 未结 1 1137
慢半拍i
慢半拍i 2021-01-15 00:03

I am working on an SMS receiver module in my app in which I am receiving an sms with my app, and if sms is more than 160 characters than I have to concate that SMS with its

相关标签:
1条回答
  • 2021-01-15 00:43

    Yes, try as handle multipart messages :

    @Override
            public void onReceive(Context context, Intent intent) {
                      Bundle bundle = intent.getExtras();
                      if (bundle != null) {
                       Object[] pdus = (Object[])bundle.get("pdus");
                       final SmsMessage[] messages = new SmsMessage[pdus.length];
                       for (int i = 0; i < pdus.length; i++) {
                          messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                        }
                           StringBuffer content = new StringBuffer();
                            if (messages.length > 0) {
                            for (int i = 0; i < messages.length; i++) {
                                content.append(messages[i].getMessageBody());
                                  }
                              }
                             String mySmsText = content.toString();
                            }
                        }
    
                    }
    
    0 讨论(0)
提交回复
热议问题