In Android, SMS is also a type of broadcast. When a text message is sent, the system sends a broadcast. We only need to process broadcast events to read text messages.
Read text message code 1:
Public class smsreceiver extends broadcastreceiver {<br/> Public final static smsmessage [] getmessagesfromintent (intent) {<br/> bundle = intent. getextras (); <br/> Object messages [] = (object []) bundle. get ("PDUS"); <br/> smsmessage msmsmessage [] = new smsmessage [messages. length]; <br/> for (INT I = 0; I <messages. length; I ++) {<br/> msmsmessage [I] = smsmessage. createfrompdu (byte []) messages [I]); <br/>}</P> <p> return msmessage; </P> <p >}< br/>}
Read text message code 2:
/*** Get sms ** @ Param intent * @ return */public final static smsmessage [] getmessagesfromintent (intent) {object [] messages = (object []) intent. getserializableextra ("PDUS"); byte [] [] pduobjs = new byte [messages. length] []; for (INT I = 0; I <messages. length; I ++) {pduobjs [I] = (byte []) messages [I];} byte [] [] PDUS = new byte [pduobjs. length] []; int pducount = PDUS. length; smsmessage [] msgs = new smsmessage [pducount]; for (INT I = 0; I <pducount; I ++) {PDUS [I] = pduobjs [I]; msgs [I] = smsmessage. createfrompdu (PDUS [I]);} return msgs ;}
Note that the permission must be declared in androidmanifest. xml.
<Cycler Android: Name = ". smsreceiver "Android: enabled =" true "> <br/> <intent-filter> <br/> <action Android: Name =" android. provider. telephony. sms_received "/> <br/> </intent-filter> <br/> </Cycler> <br/>
The preceding content is to be continued ....