实验目的:

  1. 掌握线程的基本使用

  2. 增加学习Android的兴趣

Java代码实现循环发送短信

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去除标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        
        //开启子线程 while循环发送短信
        new Thread(new Runnable() {

            public void run() {
                while(true){
                    SystemClock.sleep(2000);
                    android.telephony.SmsManager smsManager=android.telephony.SmsManager.getDefault();
                    smsManager.sendTextMessage("5556",         //目标手机号码
                            null,          //短信中心号码
                            "KZQQ10000",   //要发送的内容
                            null,         //(发送成功 回调次广播 告知我们)
                            null);         //对方接收成功 回调次广播
                }
              
            }
        }).start();
        
    }

实现效果