我想从特定号码读取短信然后删除而不将其保存在收件箱中。下面是我读取短信的代码,但此代码将短信保存在收件箱中。阅读后如何从特定号码中删除短信?
public class SmsReceiver extends BroadcastReceiver
{
public static String SMSstr;
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
String phNum = msgs[i].getOriginatingAddress();
str += msgs[i].getMessageBody().toString();
if ("15555215556".equals(phNum))
{
// delete code goes here
Intent l = new Intent(context,AgAppMenu.class);
l.putExtra("msg",str);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(l);
Toast.makeText(context, "SucessFull Login", Toast.LENGTH_SHORT).show();
}
}
<receiver android:name=".SmsReceiver" android:enabled="true">
<!-- <intent-filter >-->
<intent-filter android:priority="1000">
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>