如何集成MOB短信验证SDK?(我是用AS集成的)
SDK中的jar包和aar包地址:http://pan.baidu.com/s/1miMw5Na
快速集成MOB短信验证SDK主要分为以下几个步骤
1.新建priject
2.把sdk中的jar和aar文件分别考入libs中
3.添加依赖
3.1 jar包依赖 就是 点击jar包 右击 as library
3.2 aar包依赖 (包括资源文件的包,GUI什么东西)
aar包依赖比较麻烦:
一. targetSdkVersion 改为22
二:添加依赖仓库defaultConfig { applicationId "com.example.boom.messageproject" minSdkVersion 17 <span style="color:#ff0000;"><strong>targetSdkVersion 22</strong></span> versionCode 1 versionName "1.0" }
三:添加依赖包 (aar文件的 jar的会自动生成)<span style="font-size:18px;"> <strong><span style="color:#ff0000;"> repositories{ flatDir{ dirs 'libs' } }</span></strong></span>
<span style="font-size:18px;"> <span style="color:#ff0000;"><strong> compile(name: 'SMSSDK-2.1.1', ext: 'aar') compile(name: 'SMSSDKGUI-2.1.1', ext: 'aar')</strong></span></span>
4.配置文件
1.权限:
<span style="font-size:18px;"> <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" /></span>
2.sdk中的activity
3.application改成自己的<span style="font-size:18px;"> <activity android:name="com.mob.tools.MobUIShell" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|screenSize" android:windowSoftInputMode="stateHidden|adjustResize"/></span>
<span style="font-size:18px;"> <application android:name=".application.App" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> </application></span>
上面,我们把aar和jar都集成了。那让我看看怎么用的?
首先,我们先看看我自己写的这个project
XML代码如下:
JAVA代码如下:<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".activity.MainActivity"> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click1" android:textSize="16sp" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Click2" android:textSize="16sp" /> </LinearLayout> </span>
<span style="font-size:18px;">package com.example.boom.messageproject.activity; import android.app.Activity; import android.os.Bundle; import android.view.View; import com.example.boom.messageproject.R; import java.util.HashMap; import cn.smssdk.EventHandler; import cn.smssdk.SMSSDK; import cn.smssdk.gui.ContactsPage; import cn.smssdk.gui.RegisterPage; public class MainActivity extends Activity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init() { findViewById(R.id.btn1).setOnClickListener(this); findViewById(R.id.btn2).setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: //打开注册页面 <span style="color:#ff0000;">RegisterPage registerPage = new RegisterPage(); registerPage.setRegisterCallback(new EventHandler() { public void afterEvent(int event, int result, Object data) { // 解析注册结果 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(getBaseContext());</span> break; case R.id.btn2: <span style="color:#ff0000;"> //打开通信录好友列表页面 ContactsPage contactsPage = new ContactsPage(); contactsPage.show(getBaseContext());</span> break; } } } </span>
初始化代码,我是放在一个自定义的application中
<span style="font-size:18px;">package com.example.boom.messageproject.application; import android.app.Application; import cn.smssdk.SMSSDK; /** * Created by Boom on 2016/8/1. */ public class App extends Application { @Override public void onCreate() { super.onCreate(); SMSSDK.initSDK(this, "key", "serect"); } } </span>
注册效果展示![]()
打开好友列表界面效果展示
之后,我来介绍一下无GUI是怎么做的。