页面最后动图转换:http://blog.csdn.net/kokopop_sehun/article/details/77327519
1.这里是验证界面操作
public class YanZhengActivity extends AppCompatActivity implements View.OnClickListener{
private Button duanxin,tijiao;
private EditText ma,phonenumber;
private int i = 60;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yanzheng);
//找控件
duanxin = (Button) findViewById(R.id.duanxin);
tijiao = (Button) findViewById(R.id.tijiao);
ma = (EditText) findViewById(R.id.ma);
phonenumber = (EditText) findViewById(R.id.phonenumber);
duanxin.setOnClickListener(this);
tijiao.setOnClickListener(this);
MobSDK.init(this, "1c0e2609bb4aa", "a941cdb1b2e606adc23902d0f08b60cf");
SMSSDK.registerEventHandler(eh);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.duanxin:
SMSSDK.getVerificationCode("86", phonenumber.getText().toString().trim(), new OnSendMessageHandler(){
@Override
public boolean onSendMessage(String s, String s1) {
return false;
}
});
break;
case R.id.tijiao:
SMSSDK.submitVerificationCode("86", phonenumber.getText().toString().trim(), ma.getText().toString().trim());
break;
}
}
EventHandler eh=new EventHandler(){
@Override
public void afterEvent(int event, int result, Object data) {
if (result == SMSSDK.RESULT_COMPLETE) {
//回调完成
if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
//提交验证码成功
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(YanZhengActivity.this, MainActivity.class);
startActivity(intent);
Toast.makeText(YanZhengActivity.this, "验证成功", Toast.LENGTH_SHORT).show();
}
});
}else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE){
//获取验证码成功
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(YanZhengActivity.this, "获取验证码成功", Toast.LENGTH_SHORT).show();
}
});
}else if (event ==SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES){
//返回支持发送验证码的国家列表
}
}else{
((Throwable)data).printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(YanZhengActivity.this, "失败", Toast.LENGTH_SHORT).show();
}
});
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
SMSSDK.unregisterEventHandler(eh);
}
}
2.这里是验证界面布局:
<EditText
android:id="@+id/phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/duanxin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="短信验证"
android:layout_gravity="center"/>
<EditText
android:id="@+id/ma"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/tijiao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交验证码"
android:layout_gravity="center"/>
3.效果图如下: