Can we delete an SMS in Android before it reaches the inbox?

后端 未结 5 1466
挽巷
挽巷 2020-11-22 16:16

I am deleting an SMS from the inbox but I want to know: How can I delete it before it reaches the inbox?

5条回答
  •  面向向阳花
    2020-11-22 16:27

    Step-1: Create your custom broadcast receiver to receive sms. write the logic to abort the broadst so that the message will not be available to your inbox

    public class SMSReceiver extends BroadcastReceiver
    {
        public void onReceive(Context context, Intent intent)
        {
         if(conditionMatches){
         abortBroadcast();
         }
        }
    }
    

    Step-2 Register broadcast receiver in AndoridManifest and put android:priority value a large number

    
                
                    
                
            
    

    Thats It

    How does the above code work

    As SMS receiving broad cast is an ordered broadcast the receiver with high priority will receive first so your application receive first and after receiving you are aborting broadcast. So no other application can receive it. Hence the sms will not exist in inbox

提交回复
热议问题