Directly give the code:
[Html]
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 ";
@ Override
Public void onReceive (Context context, Intent intent)
{
String msgContent = "";
String functiontype = "";
Bundle bundle = intent. getExtras ();
Object messages [] = (Object []) bundle. get ("pdus ");
SmsMessage 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. inclusignorecase ("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 context, String smscontent)
{
Try
{
// Prepare the uri address 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 (); // obtain the sender
String body =
IsRead. getString (isRead. getColumnIndex ("body"). trim (); // get information
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 ();
}
}
}
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 ";
@ Override
Public void onReceive (Context context, Intent intent)
{
String msgContent = "";
String functiontype = "";
Bundle bundle = intent. getExtras ();
Object messages [] = (Object []) bundle. get ("pdus ");
SmsMessage 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. inclusignorecase ("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 context, String smscontent)
{
Try
{
// Prepare the uri address 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 (); // obtain the sender
String body =
IsRead. getString (isRead. getColumnIndex ("body"). trim (); // get information
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 ();
}
}
}
[Html]
<! -- Register the aggreger and set the priority -->
<Cycler
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>
<! -- Register the aggreger and set the priority -->
<Cycler
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:
[Html]
<Uses-permission android: name = "android. permission. RECEIVE_SMS"/>
<Uses-permission android: name = "android. permission. READ_SMS"/>
<Uses-permission android: name = "android. permission. WRITE_SMS"/>
<Uses-permission android: name = "android. permission. RECEIVE_SMS"/>
<Uses-permission android: name = "android. permission. READ_SMS"/>
<Uses-permission android: name = "android. permission. WRITE_SMS"/>