Android – Listen For Incoming SMS Messages

后端 未结 9 1556
情话喂你
情话喂你 2020-11-22 07:06

I am trying to create an application for monitoring incoming SMS messages, and launch a program via incoming SMS, also it should read the content from the SMS.

Workf

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 07:29

    public class SmsListener extends BroadcastReceiver{
    
        private SharedPreferences preferences;
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
    
            if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
                Bundle bundle = intent.getExtras();           //---get the SMS message passed in---
                SmsMessage[] msgs = null;
                String msg_from;
                if (bundle != null){
                    //---retrieve the SMS message received---
                    try{
                        Object[] pdus = (Object[]) bundle.get("pdus");
                        msgs = new SmsMessage[pdus.length];
                        for(int i=0; i

    Note: In your manifest file add the BroadcastReceiver-

    
        
            
        
    
    

    Add this permission:

    
    

提交回复
热议问题