mob短线简单验证,具体逻辑在添加

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();
            }
        });
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值