首页 » Android » 短信验证

短信验证

原文 http://blog.csdn.net/qq_40239712/article/details/78012275

2017-09-17 20:20:19阅读(804)

1.在mob的官网上下载集成好 短信验证码SDK

2.找到mob的短信SMS Android 集成文档

按照里面的方法,进行把所需要的jar放入libs里面


3.在Module的build.gradle里面将libs加入仓库(repositories):

repositories{
    flatDir{
        dirs 'libs' 
    }
}

4.在Module的build.gradle里面添加依赖(dependencies ):

dependencies {
    ....//你的其他依赖
    compile name:'SMSSDK-3.0.0',ext:'aar'
    compile name:'SMSSDKGUI-3.0.0',ext:'aar'
}
5.配置AndroidManifest.xml

5.1、添加以下权限:

<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" />

5.2、添加以下Activity:

<activity
   android:name="com.mob.tools.MobUIShell"
   android:theme="@android:style/Theme.Translucent.NoTitleBar"
   android:configChanges="keyboardHidden|orientation|screenSize"
   android:windowSoftInputMode="stateHidden|adjustResize"/>

6.在Application里面添加,这些都在你登录过的后台的设置里面获取,要在Manifest.xml里面进行注册

// 通过代码注册你的AppKey和AppSecret
MobSDK.init(context, "你的AppKey", "你的AppSecret");

7.主类中,布局中 有个Button按钮

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

      //初始化控件

        Button button = (Button) findViewById(R.id.denglu);

      //进行监听

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

             //打开注册界面

                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");

                        }
                    }
                });
                registerPage.show(MainActivty.this);
             
            }
        });



最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹