0
点赞
收藏
分享

微信扫一扫

Android中短信发送倒计时方法

芥子书屋 2022-08-23 阅读 119


// 验证码等待

private int time = 90;

private static final int MSG_TIME = 0;

private static final int MAX_TIME = 90;

Handler handler = new Handler() {

@Override

public void handleMessage(Message msg) {

super.handleMessage(msg);

switch (msg.what) {

case MSG_TIME:

if (time>0) {

time--;

get_verifyTextView.setText("重新获取" + time);



handler.sendEmptyMessageDelayed(MSG_TIME, 1000);

Log.i("TAG", "不停发消息的事件"+time);

} else {

get_verifyTextView.setText("获取验证码");

time = MAX_TIME;

}

break;



}

}

};





/**点击监听*/

@Override

public void onClick(View v) {

String tel = telEditText.getText().toString();

String input_verify = verifyEditText.getText().toString();

switch (v.getId()) {

case R.id.tv_get_verify_phone:

// 如果手机号与原来相同,不做请求



// 正确格式手机号

if (!ValidateUtil.isMobileNO(tel)) {

ShowDialog(MyApplication.mResources.getString(R.string.test_tel));

return;

}

// 90秒内不重新发送

if (time != 90&&time!=-1) {

UIHelper.showToast(this, time + "秒后可重新获取验证码");

return;

}




MyApplication.mRequestManager.getVerify(tel, this);

TemporaryTel = tel;

break;

举报

相关推荐

0 条评论