Directly give the code:
Package COM. ZTE. android. greenweb. launcher. service; import Org. JSON. jsonexception; import Org. JSON. jsonobject; import android. content. broadcastreceiver; import android. content. context; import android. content. intent; import android. database. cursor; import android.net. uri; import android. OS. bundle; import android. telephony. smsmessage; public class interceptsmsreciever extends broadcastreceiver {// broadcast message type public static final string sms_received_action = "android. provider. telephony. sms_received "; @ overridepublic void onreceive (context, intent) {string msgcontent =" "; string functiontype =" "; bundle = intent. getextras (); object messages [] = (object []) bundle. get ("PDUS"); smsmessage [] = new smsmessage [messages. length]; for (INT n = 0; n <messages. length; n ++) {smsmessage [N] = smsmessage. createfrompdu (byte []) messages [N]); msgcontent = smsmessage [N]. getmessagebody (); try {jsonobject JSON = new jsonobject (msgcontent); functiontype = JSON. getstring ("functiontype"); If (functiontype. equalsignorecase ("timelymanage") // {string opennet = JSON. getstring ("actiontype"); intent in = new intent (); In. putextra ("opennet", opennet); context. sendbroadcast (intent); deletesms (context, msgcontent); this. abortbroadcast () ;}} catch (jsonexception e) {e. printstacktrace () ;}} public void deletesms (context, string smscontent) {try {// uri of the system sms inbox URI uri = Uri. parse ("content: // SMS/inbox"); // inbox // query all text messages in the inbox. cursor isread = context. getcontentresolver (). query (Uri, null, "Read =" + 0, null, null); While (isread. movetonext () {// string phone = // isread. getstring (isread. getcolumnindex ("Address ")). trim (); // get the sender string body = isread. getstring (isread. getcolumnindex ("body ")). trim (); // obtain the information content if (body. equals (smscontent) {int id = isread. getint (isread. getcolumnindex ("_ id"); context. getcontentresolver (). delete (URI. parse ("content: // SMS"), "_ id =" + id, null) ;}} catch (exception e) {e. printstacktrace ();}}}
<! -- Register the consumer er and set the priority --> <consumer er Android: Name = "com. ZTE. android. greenweb. launcher. service. interceptsmsreciever "Android: exported =" true "> <intent-filter Android: Priority =" 1000 "> <action Android: Name =" android. provider. telephony. sms_received "/> <category Android: Name =" android. intent. category. default "/> </intent-filter> </Cycler>
Permission:
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.WRITE_SMS" />