package com.example.myapplication; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.EventLogTags; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.util.HashMap; import cn.smssdk.EventHandler; import cn.smssdk.SMSSDK; import cn.smssdk.gui.RegisterPage; public class DuanxinMainActivity extends AppCompatActivity { private static final String TAG = "DuanxinMainActivity"; Button button; EditText editText; String phone; Button button1; EditText editText1; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { int event = msg.arg1; int result = msg.arg2; if (result == SMSSDK.RESULT_COMPLETE) { if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {// 提交验证码成功 Toast.makeText(getApplicationContext(), "提交验证码成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "验证码已经发送请注意查收", Toast.LENGTH_SHORT).show(); } } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_duanxin_main); SMSSDK.initSDK(this, "1b85abc065414", "cf75d689b3609b9c018664002d021767"); 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); setview(); } private void setview() { button = (Button) findViewById(R.id.button); editText = (EditText) findViewById(R.id.editText); button1 = (Button) findViewById(R.id.button2); editText1 = (EditText) findViewById(R.id.editText2); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SMSSDK.submitVerificationCode("86", phone, editText1.getText().toString()); Log.i(TAG, "result: =" + editText1.getText().toString()); } }); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { phone = editText.getText().toString(); SMSSDK.getVerificationCode("86", phone); Log.i(TAG, "result: =" + phone); // RegisterPage registerPage = new RegisterPage(); // registerPage.setRegisterCallback(new EventHandler() { // public void afterEvent(int event, int result, Object data) { // // 解析注册结果 // Log.i(TAG, "result: ="+result); // if (result == SMSSDK.RESULT_COMPLETE) { // @SuppressWarnings("unchecked") // HashMap<String,Object> phoneMap = (HashMap<String, Object>) data; // String country = (String) phoneMap.get("country"); // String phone = (String) phoneMap.get("phone"); // 提交用户信息(此方法可以不调用) registerUser(country, phone); // } // } // }); // registerPage.show(DuanxinMainActivity.this); } }).start(); } }); } }