Android SMS Receiver not working

后端 未结 5 844
南旧
南旧 2020-12-11 13:23

I am new to android programming please help me in resolving a problem.

My code to receive sms is not working.

the manifest file is

<         


        
5条回答
  •  不思量自难忘°
    2020-12-11 13:59

    package com.google.android;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.telephony.SmsMessage;
    import android.widget.Toast;
    
    public class SMSReceiver extends BroadcastReceiver {    
        @Override /** This line is important, as you have not overriden the original method*/
        public void onReceive(Context context, Intent intent) {
            //---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

    I hope this will help you.

提交回复
热议问题