一、注册mob账号并登陆 官网http://www.mob.com/#/
账户:[email protected] 密码:tmy2016
二、进入短信注册后台 网址:http://dashboard.mob.com/#/sms/index
添加应用
生成应用信息
三、下载短信验证sdk 地址:http://www.mob.com/#/downloadDetail/SMS/android
解压后的文件为
四、导入
分别设置成库项目项目
右键选择properties-->Android -->勾选is Library-->Apply-->OK
五、新建项目
右键选择properties-->Android -->Add-->OK-->Apply-->OK
代码实现:1>MoocActivity.Java
public class MoocActivity extends Activity {
Button mBtnBindPhone;
String APPKEY="15864f2b39d2e";
String APPSECRETE="05c7acf81f9bc63331ec8244f5826adc";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mooc);
//初始化
SMSSDK.initSDK(this, APPKEY, APPSECRETE);
//配置信息AndroidManifest.xml
mBtnBindPhone=(Button)findViewById(R.id.btn_bind_phone);
mBtnBindPhone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// 注册手机号
RegisterPage registerPage=new RegisterPage();
//注册回调事件
registerPage.setRegisterCallback(new EventHandler(){
//事件完成后调用
@Override
public void afterEvent(int event, int result, Object data) {
//判断结构是否完成
if(result==SMSSDK.RESULT_COMPLETE){
//获取数据data
HashMap<String, Object> maps=(HashMap<String, Object>) data;
//国家
String country=(String) maps.get("country");
//手机号
String phone=(String) maps.get("phone");
submitUserInfo(country, phone);
Toast.makeText(MoocActivity.this, "phone:"+phone+"country:"+country, Toast.LENGTH_SHORT).show();;
}
//super.afterEvent(arg0, arg1, arg2);
}
});
//显示注册页面
registerPage.show(MoocActivity.this);
}
});
}
/*
* 提交用户信息
* */
public void submitUserInfo(String country,String phone){
Random r=new Random();
String uid=Math.abs(r.nextInt())+"";
String nickName="tmy";
SMSSDK.submitUserInfo(uid, nickName, null, country, phone);
}
}
2>activity_mooc.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_bind_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册或者绑定手机号" />
</LinearLayout>
3>AndroidManifest.xml
添加如下代码<!-- 配置的网络权限 -->
<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.READ_SMS" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<activity
android:name="com.mob.tools.MobUIShell"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize"/>
好啦,运行效果图