官方网站:www.mob.com

注册帐号,下载SDK,导入SDK就不说了,主要写一下简单集成如何使用,以后忘记了也可以翻着看看。

详细的可以参考官方文档:

  http://wiki.mob.com/android-%E7%9F%AD%E4%BF%A1sdk%E6%93%8D%E4%BD%9C%E5%9B%9E%E8%B0%83/

  http://wiki.mob.com/sms-android-%E6%97%A0gui%E6%8E%A5%E5%8F%A3%E8%B0%83%E7%94%A8/

  步骤大致可以分为:

看代码:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.lixyz.records"
android:versionCode="1"
android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" />
<!-- 为SMSDK添加的权限 -->
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="cn.lixyz.records.activity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="cn.lixyz.records.activity.RegisterActivity" />
<activity android:name="cn.lixyz.records.activity.IndexActivity" />
<activity
android:name="com.mob.tools.MobUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" />
</application> </manifest>

RegisterActivity.java

package cn.lixyz.records.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import cn.lixyz.records.R;
import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK; public class RegisterActivity extends Activity implements OnClickListener { private Button bt_reg_getauthcode, bt_reg_sumbit;
private EditText et_reg_phone, et_reg_authcode, et_reg_password, et_reg_againpass; // 用于发送message,表示更改按钮上的倒计时
public static final int CHANGE_TIME = 100;
// 用户发送message,表示可以重新获取验证码
public static final int AGAIN_GET_AUTHCODE = 200; int i = 30; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register); initView(); SMSSDK.initSDK(this, "xxxxxxxxx", "xxxxxxxxxxxxxxxx"); 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); bt_reg_getauthcode.setOnClickListener(this);
bt_reg_sumbit.setOnClickListener(this);
} private void initView() {
bt_reg_getauthcode = (Button) findViewById(R.id.bt_reg_getauthcode);
bt_reg_sumbit = (Button) findViewById(R.id.bt_reg_sumbit);
et_reg_phone = (EditText) findViewById(R.id.et_reg_phone);
et_reg_authcode = (EditText) findViewById(R.id.et_reg_authcode);
et_reg_password = (EditText) findViewById(R.id.et_reg_password);
et_reg_againpass = (EditText) findViewById(R.id.et_reg_againpass);
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_reg_getauthcode:
sendAuthCode();
break; case R.id.bt_reg_sumbit:
registe();
break;
}
} // 注册方法
private void registe() {
String inputAuthCode = et_reg_authcode.getText().toString();
String password = et_reg_password.getText().toString();
String str = et_reg_againpass.getText().toString();
if (str.equals(password)) {
SMSSDK.submitVerificationCode("86", et_reg_phone.getText().toString(), inputAuthCode);
} else {
Toast.makeText(getApplicationContext(), "您的密码输入不一致", Toast.LENGTH_SHORT).show();
}
} // 发送验证码
private void sendAuthCode() {
// 获取用户输入的手机号
String phoneNumber = et_reg_phone.getText().toString();
// 请求获取验证码
SMSSDK.getVerificationCode("86", phoneNumber);
// 将获取验证码按钮设置为不可点击
bt_reg_getauthcode.setClickable(false);
// bt_reg_getauthcode.setText("重新发送(" + i + ")");
new Thread(new Runnable() {
@Override
public void run() {
// 循环30秒,用于更新按钮上的倒计时
for (; i > 0; i--) {
handler.sendEmptyMessage(CHANGE_TIME);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 30秒完成,可以重新获取验证码
handler.sendEmptyMessage(AGAIN_GET_AUTHCODE);
}
}).start(); } Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == CHANGE_TIME) {
bt_reg_getauthcode.setText("重新发送(" + i + ")");
} else if (msg.what == AGAIN_GET_AUTHCODE) {
bt_reg_getauthcode.setClickable(true);
bt_reg_getauthcode.setText("获取验证码");
i = 30;
} else {
int event = msg.arg1;
int result = msg.arg2;
Object data = msg.obj;
Log.d("TTTT", "event=" + event + ",result=" + result);
// 如果等于-1,表示事件执行成功
if (result == -1) {
if (event == 3) {
Toast.makeText(getApplicationContext(), "提交验证码成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
startActivity(intent);
} else if (event == 2) {
Toast.makeText(getApplicationContext(), "验证码已经发送", Toast.LENGTH_SHORT).show();
}
} else if (result == 0) {
if (event == 3) {
Toast.makeText(getApplicationContext(), "验证码错误,请检查", Toast.LENGTH_SHORT).show();
}
}
}
};
}; protected void onDestroy() {
SMSSDK.unregisterAllEventHandler();
};
}

activity_register.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" > <EditText
android:id="@+id/et_reg_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="输入您的手机号" /> <Button
android:id="@+id/bt_reg_getauthcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="获取验证码" />
</LinearLayout> <EditText
android:id="@+id/et_reg_authcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入您收到的验证码" /> <EditText
android:id="@+id/et_reg_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="请输入您的密码"
android:password="true" /> <EditText
android:id="@+id/et_reg_againpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="重复您的密码"
android:password="true" /> <Button
android:id="@+id/bt_reg_sumbit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="注 册" /> </LinearLayout>

  

Android笔记(五十一) 短信验证码集成——mob平台的更多相关文章

  1. 转载:Android自动化测试- 自动获取短信验证码

    前言:android应用的自动化测试必然会涉及到注册登录功能,而许多的注册登录或修改密码功能常常需要输入短信验证码,因此有必要能够自动获得下发的短信验证码. 主要就是实时获取短信信息. android ...

  2. ShareSDK短信验证码集成详细步骤

    1.这里使用的是ShareSDK网的短信验证码SDK  官网 http://www.mob.com 先去http://www.mob.com/#/reg 注册成为开发者 填写相应的信息,邮箱账号,然后 ...

  3. Android学习笔记之短信验证码的获取和读取

    PS:最近很多事情都拖拖拉拉的..都什么办事效率啊!!! 还得吐槽一下移动运营商,验证码超过五次的时候,直接把我的手机号封闭.真是受够了. 学习笔记: 1.Android之如何获取短信验证码. 2.如 ...

  4. sharesdk短信验证码的集成

    在ShareSDK官网http://mob.com/注册并创建Android应用.申请APP_key,下载SDK等 根据官网开发文档导入SDK,目录结构如下 将以上文件按需放入Android Stud ...

  5. Android Studio精彩案例(五)《JSMS短信验证码功能实现》

    转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 很多应用刚打开的时候,让我们输入手机号,通过短信验证码来登录该应用.那么,这个场景是怎么实现的呢?其实是很多开放平台提供了短信验证功能 ...

  6. SpringBoot + Spring Security 学习笔记(五)实现短信验证码+登录功能

    在 Spring Security 中基于表单的认证模式,默认就是密码帐号登录认证,那么对于短信验证码+登录的方式,Spring Security 没有现成的接口可以使用,所以需要自己的封装一个类似的 ...

  7. Android之短信验证码

    我们今天所使用的方案仅仅是android手机设备集成短信验证码功能的方案之中的一个. 我们所採用的方案是使用聚合数据的短信验证sdk. 程序的界面例如以下所看到的: 实现步骤: 1.到聚合数据官网上申 ...

  8. Android开发之短信验证码示例

    在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...

  9. Android获取短信验证码

    Android开发中关于短息验证码的设计层出不穷,越来越多的应用为了更好的提高软件的安全性,开始使用通过服务器向用户发送验证码的方式,来保护用户个人信息的安全性.无论是用户注册时的信息验证还是当用户发 ...

随机推荐

  1. linux命令(11)环境变量:查看和添加环境变量

    linux 环境变量系统: 系统级别:/etc/profile./etc/bashrc/ ./etc/environment 用户级别:~/.profile.~/.bashrc. ~/.bash_pr ...

  2. C# Newtonsoft.Json解析json字符串处理(最清晰易懂的方法)

    需求: 假设有如下json字符串: { ", "employees": [ { "firstName": "Bill", &quo ...

  3. Spring cloud微服务安全实战-7-5配置grafana图表及报警

    先过一下grafana的配置文件 grafana的配置文件. 右键服务的地址.发信人 账号 和面等 配置要连到prometheus上. 登陆的密码是多少,第二行是不允许用户注册. dashboard. ...

  4. oracle plsql 异常

      set serveroutput on DECLARE pename emp.ename%type; begin '; exception when no_data_found then dbms ...

  5. 【翻译】Flink Table Api & SQL —— Table API

    本文翻译自官网:Table API  https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/table/tableApi.ht ...

  6. SQL Server导入Excel文件报错

    目录 文本被截断,或者一个或多个字符在目标代码页中没有匹配项 原因 解决方法 该值违反了该列的完整性约束 空行 没有设置为允许为NULL 我以前也导入过数据,也没报错,今天再次导入数据的时候,发现了两 ...

  7. 在使用redis做缓存后,mybatis的延迟加载失效

    原来使用的是EHcache,mybatis延迟加载没有问题,改成redis后,延迟加载获得数据时就会发生错误. 报:Cannot get Configuration as configuration ...

  8. 警方破获超大DDoS黑产案,20万个僵尸网络运营商被抓

    中国警方已镇压并逮捕了一个犯罪集团,该集团经营着一个由200,000多个受感染网站构成的僵尸网络,这些网站被用来发起DDoS攻击. 这是中国当局针对兴旺的本地DDoS租用场景进行的首次重大镇压,最大的 ...

  9. Ubuntu查看与结束任务进程

    1.打开终端 2.敲  ps -ef  查出进程的编号(就是PID那列) 3.输入 kill PID 即可(如果PID是123456,则kill 123456) 例如: 我想把splash关闭,直接输 ...

  10. log sum of exponential

    The so-called “log sum of exponentials” is a functional form commonly encountered in dynamic discret ...