How to analyze incoming SMS on Android?

前端 未结 3 678
遇见更好的自我
遇见更好的自我 2020-12-04 17:23

How can I code in Android such that my app can analyze an incoming SMS and perhaps block it or do something(maybe move to a different SMS folder) BEFORE the SMS actually rai

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 17:51

    I use this code, as a BroadcastReceiver:

    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 = "";            
        if (bundle != null)
        {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];            
            for (int i=0; i

    remember to add it in manifest and add a higgest priority (100) for broadcast or sms will go first to inbox and get the alert notification.

        
            
                
            
        
    

    Hope it helps you.

提交回复
热议问题