SMS手机验证

下载SDK  android studio 

http://www.mob.com/downloadDetail/SMS/android

查看适配

http://wiki.mob.com/android-短信sdk集成文档/

导入四个jar

打开您项目的“AndroidManifest.xml”,在其中添加如下的权限:

android:name="android.permission.READ_CONTACTS" />
android:name="android.permission.READ_PHONE_STATE" />
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
android:name="android.permission.ACCESS_NETWORK_STATE" />
android:name="android.permission.ACCESS_WIFI_STATE" />
android:name="android.permission.INTERNET" />
android:name="android.permission.RECEIVE_SMS" />
android:name="android.permission.READ_SMS" />
android:name="android.permission.GET_TASKS" />
android:name="android.permission.ACCESS_FINE_LOCATION" />
然后在“application”下添加如下activity:

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

//写下中间
compile name: 'SMSSDK-2.1.3', ext: 'aar'
compile name: 'SMSSDKGUI-2.1.3', ext: 'aar'
//

repositories {
    flatDir {
        dirs 'libs'
    }
}


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.util.HashMap;

import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import cn.smssdk.gui.RegisterPage;

public class MainActivity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.shouji);
        //初始化SMSSDK
        SMSSDK.initSDK(this, "1c0e2609bb4aa", "a941cdb1b2e606adc23902d0f08b60cf");

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开注册页面
                final RegisterPage registerPage = new RegisterPage();
                registerPage.setRegisterCallback(new EventHandler() {
                    @Override
                    public void afterEvent(int event, int result, Object data) {
                        super.afterEvent(event, result, data);
                        //解析注册结果
                        if (result == SMSSDK.RESULT_COMPLETE) {
                            HashMap, Object> map = (HashMap, Object>) data;
                            String country = (String) map.get("country");
                            String phone = (String) map.get("phone");
                        }
                    }
                });
                registerPage.show(MainActivity.this);
            }
        });
    }
}


你可能感兴趣的:(SMS手机验证)