我想從特定號碼讀取短信,然後刪除而不將其保存在收件箱中。下面是我的代碼,它讀取短信,但此代碼將SMS保存在收件箱中。 如何在閱讀後從特定號碼中刪除短信?如何閱讀短信並刪除而不保存在收件箱中
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>
請幫我me –