如何阅读短信和删除不保存在收件箱中 [英] How to read sms and delete without save in inbox
本文介绍了如何阅读短信和删除不保存在收件箱中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读短信,从特定的号码,然后删除,但不保存在收件箱中。下面是我的code的读取短信但这code保存的短信收件箱。 我该怎么办删除特定号码短信读取之后呢?
公共类SmsReceiver扩展的BroadcastReceiver
{
公共静态字符串SMSstr;
公共无效的onReceive(上下文的背景下,意图意图)
{
// ---得到通过短信---
捆绑包= intent.getExtras();
SmsMessage []封邮件= NULL;
字符串str =;
如果(捆绑!= NULL)
{
// ---检索收到的短信---
[对象]的PDU =(对象[])bundle.get(的PDU);
封邮件=新SmsMessage [pdus.length]
的for(int i = 0; I< msgs.length;我++){
封邮件[I] = SmsMessage.createFromPdu((字节[])的PDU [I]);
字符串普农=封邮件[I] .getOriginatingAddress();
STR + =封邮件[I] .getMessageBody()的toString()。
如果(15555215556.equals(普农))
{
//删除code到这里
意图L =新的意图(背景下,AgAppMenu.class);
l.putExtra(味精,STR);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(升);
Toast.makeText(上下文中,SucessFull登录,Toast.LENGTH_SHORT).show();
}
}
<接收机器人:SmsReceiver名称=机器人:启用=真正的>
&所述;! - &所述;意图滤光器> - >
<意图过滤器的Android版本:优先=1000>
<作用机器人:名称=
android.provider.Telephony.SMS_RECEIVED/>
&所述; /意图滤光器>
< /接收器>
解决方案
如果你想删除的邮件只需调用 abortBroadcast()
后您检查所需的源!
I want to read a sms from specific number then delete without saving it in inbox. Below is my code which read sms but this code saves the SMS in the inbox. How can I do delete a sms from specific number after read it?
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>
解决方案
If you want to delete the message simply call the abortBroadcast()
after you check for the desired source!
这篇关于如何阅读短信和删除不保存在收件箱中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文