博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mob短信
阅读量:6619 次
发布时间:2019-06-25

本文共 4800 字,大约阅读时间需要 16 分钟。

hot3.png

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(); // 注销回调接口    }}

转载于:https://my.oschina.net/u/3705875/blog/1570010

你可能感兴趣的文章
自己模拟写C++中的String类型
查看>>
Java英文单词Java基础常见英语词汇
查看>>
Faster R-CNN:详解目标检测的实现过程
查看>>
kali下更新软件时,总是报错,说下列签名无效 解决办法
查看>>
Oracle 11gR2 create init script
查看>>
手机端网页web开发要点
查看>>
silverlight水印
查看>>
微软职位内部推荐-Software Engineer II
查看>>
LeetCode-3:Longest Substring Without Repeating Characters
查看>>
MSIL条件跳转(简单注释)
查看>>
学习MSCOREE.dll是托管程序的入口点
查看>>
bbc--平台点击进入详情页配置
查看>>
ORACLE存储过程 练习系列六 关键字 分页查询某个方案下的建表语句
查看>>
JavaScript设计模式 代理模式
查看>>
Uiautomator 2.0之UiDevice新增API学习小记
查看>>
在MS Test中如何测试private方法
查看>>
.net4.0中json时间转换问题
查看>>
反射+特性打造简洁的AJAX调用
查看>>
挤牛奶
查看>>
给年轻程序员的几句话
查看>>