package com.example.day08_practice.fragment.myfragment.s.activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.Toast;import com.example.day08_practice.R;import cn.smssdk.EventHandler;import cn.smssdk.SMSSDK;public class MyRegisterActivity extends AppCompatActivity implements View.OnClickListener { private ImageView img_back_register; private EditText register_number; private EditText register_yanzhengma; private Button huoqu_yanzhengma; private String number; private int shu = 60; private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); int event = msg.arg1; int result = msg.arg2; Object data = msg.obj; if (result == SMSSDK.RESULT_COMPLETE) { // 如果操作成功 if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) { // 校验验证码,返回校验的手机和国家代码 Toast.makeText(MyRegisterActivity.this, "验证成功", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MyRegisterActivity.this, RegisterActivity.class); intent.putExtra("phone",number); startActivityForResult(intent,1); } else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) { // 获取验证码成功,true为智能验证,false为普通下发短信 Toast.makeText(MyRegisterActivity.this, "验证码已发送", Toast.LENGTH_SHORT).show(); } else if (event == SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES) { // 返回支持发送验证码的国家列表 } } else if (data instanceof Throwable) { Throwable throwable = (Throwable) data; String message = throwable.getMessage(); Toast.makeText(MyRegisterActivity.this, message, Toast.LENGTH_SHORT).show(); } } }; private Button btn_myregister_register; private Runnable runnable; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_register); initView(); EventHandler eventHandler = new EventHandler() { // 操作回调 @Override public void afterEvent(int event, int result, Object data) { Message msg = new Message(); msg.arg1 = event; msg.arg2 = result; msg.obj = data; handler.sendMessage(msg); } }; SMSSDK.registerEventHandler(eventHandler); // 注册回调接口 } private void initView() { img_back_register = (ImageView) findViewById(R.id.img_back_register); img_back_register.setOnClickListener(this); register_number = (EditText) findViewById(R.id.register_number); register_number.setOnClickListener(this); register_yanzhengma = (EditText) findViewById(R.id.register_yanzhengma); register_yanzhengma.setOnClickListener(this); huoqu_yanzhengma = (Button) findViewById(R.id.huoqu_yanzhengma); huoqu_yanzhengma.setOnClickListener(this); btn_myregister_register = (Button) findViewById(R.id.btn_myregister_register); btn_myregister_register.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.img_back_register: finish(); break; case R.id.huoqu_yanzhengma: number = register_number.getText().toString().trim();// if(huoqu_yanzhengma.getText().toString().equals("获取验证码")){ runnable = new Runnable() { @Override public void run() { shu--; huoqu_yanzhengma.setText("获取验证码"+shu); if(shu==0){ huoqu_yanzhengma.setText("获取验证码"); }else{ handler.postDelayed(runnable,1000); } } };// } SMSSDK.getVerificationCode("86", number); break; case R.id.btn_myregister_register: SMSSDK.submitVerificationCode("86", number, register_yanzhengma.getText().toString()); break; } } @Override protected void onDestroy() { super.onDestroy(); SMSSDK.unregisterAllEventHandler(); // 注销回调接口 }}