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