android(2)(循环发送短信)

时间:2022-12-15 15:05:09
循环发送短信:
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去除标题,必须在setContentView方法之前调用
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//开启一个子线程,while(true)循环发送短信
new Thread(new Runnable() {

@Override
public void run() {
while (true) {
//循环发送短信
try {
Thread.sleep(1000);
SystemClock.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
SmsManager smsManager = SmsManager.getDefault();//短信管理器
smsManager.sendTextMessage("123456", //destinationAddress:收件人号码
null, //scAddress:短信中心号码
"今晚小树林, 不见不散", //text:短信内容
null, //sentIntent:如果发送成功, 回调此广播, 通知我们.
null);//deliveryIntent:当对方接收成功, 回调此广播

}
}
}).start();
}