限制短信进入收件箱

发布于 2024-12-09 02:36:33 字数 1518 浏览 0 评论 0原文

我需要限制短信不保存在收件箱中。它应该保存在某个用户给定的文件夹中。为此,我使用以下代码。我可以限制短信通知。通过在我的接收器类中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝情姑娘 2024-12-16 02:36:33

只是在manifest上必须增加你的Intent的优先级,如下:

<receiver android:name=".SmsReceiver"> 
<intent-filter android:priority="100"> 
    <action android:name=
        "android.provider.Telephony.SMS_RECEIVED" /> 
</intent-filter> 

Just on the manifest must increase the priority of your Intent, as follows:

<receiver android:name=".SmsReceiver"> 
<intent-filter android:priority="100"> 
    <action android:name=
        "android.provider.Telephony.SMS_RECEIVED" /> 
</intent-filter> 

涫野音 2024-12-16 02:36:33

如果您想限制消息发送到其他应用程序存储,您必须在 nadroid.manifst 中设置应用程序的“优先级”...此处
在这种情况下,我阻止自己的短信进入我的短信应用程序存储。

=================================================== ===================

SMBROAD CAST RECEIVER CLASSS 中的代码。

  if(sender.equalsIgnoreCase("+923339736506"))
    {
       Toast.makeText(context, "you are not allowed ! ", Toast.LENGTH_SHORT).show();
                this.abortBroadcast();
      }

并在 android.manifest 中设置优先级,如下所示

       <receiver android:name=".SmsReceiver"> 

        <intent-filter android:priority="100"> 

        <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 

        </intent-filter> 

    </receiver>     

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.

  if(sender.equalsIgnoreCase("+923339736506"))
    {
       Toast.makeText(context, "you are not allowed ! ", Toast.LENGTH_SHORT).show();
                this.abortBroadcast();
      }

and setting the priority in android.manifest like this

       <receiver android:name=".SmsReceiver"> 

        <intent-filter android:priority="100"> 

        <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 

        </intent-filter> 

    </receiver>     
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文