How to Get text message content

Source: Internet
Author: User

How can I get the text message content?
1. Write a broadcast receiver class that integrates broadcastreceiver
Process broadcast in onreceive () method
Key Java code:

1 Public void onreceive (context, intent) {2 bundle = intent. getextras (); 3 if (bundle! = NULL) {4 // obtain the received data. 5 object [] objarray = (object []) bundle. get ("PDUS"); 6 // defines the smsmessage object array of SMS content. 7. smsmessage [] messages = new smessage [objarray. length]; 8 // process all received messages cyclically 9 for (INT I = 0; I <objarray. length; I ++) {10 // replace each text message data with the smsmessage object 11 messages [I] = smsmessage. createfrompdu (byte []) objarray [I]); 12 // get the phone number and content of the text message 13 string S = "mobile phone number:" + messages [I]. getoriginatingaddress () + "\ n"; 14 S = "SMS content:" + message [I]. getdisplaymessagebody (); 15 // display the phone number and content of the text message 16 toast. maketext (context, S, toast. length_long ). show (); 17} 18} 19}

2. Add the SMS broadcast action when defining the broadcast receiver category in the list file.
<Cycler Android: Name = ". receivmessagereceiver"
Android: enabled = "true">
<Intent-filter>
<Action Android: Name "android. provider. telephony. sms_received"/>
<Intent-filter>
</Cycler>

How to Get text message content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.