限制短信进入收件箱
我需要限制短信不保存在收件箱中。它应该保存在某个用户给定的文件夹中。为此,我使用以下代码。我可以限制短信通知。通过在我的接收器类中使用 this.abortBroadCast() ..但是短信显示在收件箱中。 我需要限制它进入收件箱。它应该显示在其他文件夹中。
public class SmsReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//this stops notifications to others
this.abortBroadcast();
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
boolean checksomething =true ;
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]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
}
if(checksomething){
Toast.makeText(context, "Broad Cast Cancelled", Toast.LENGTH_SHORT).show();
}else{
this.clearAbortBroadcast();
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
I need to restrict sms not to save in inbox. and it should be saved in some user given folder.For that im using bellow code. i can able to restrict sms notification. by using this.abortBroadCast() in my receiver clas.. But SMS is showing in Inbox.
I need restrict it entering into INBOX. And it shoulb shown in some other folder.
public class SmsReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//this stops notifications to others
this.abortBroadcast();
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
boolean checksomething =true ;
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]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
}
if(checksomething){
Toast.makeText(context, "Broad Cast Cancelled", Toast.LENGTH_SHORT).show();
}else{
this.clearAbortBroadcast();
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是在manifest上必须增加你的Intent的优先级,如下:
Just on the manifest must increase the priority of your Intent, as follows:
如果您想限制消息发送到其他应用程序存储,您必须在 nadroid.manifst 中设置应用程序的“优先级”...此处
在这种情况下,我阻止自己的短信进入我的短信应用程序存储。
=================================================== ===================
SMBROAD CAST RECEIVER CLASSS 中的代码。
并在 android.manifest 中设置优先级,如下所示
IF YOU WANT TO RESTRICT THE MESSAGE TO GO TO OTHER APPS STORAGE YOU HAVE TO SET THE "PRIORITY" OF YOUR APP IN nadroid.manifst... HERE IN
THIS CASE I AM BLOCKING MY OWN SMS TO GO TO MY SMS APPS STORAGE.
=====================================================================
Code in SMSBROAD CAST RECEIVER CLASSS.
and setting the priority in android.manifest like this