第一步:导入SDK所在的Libs里面
第二步:build.gradle里面将libs加入仓库(repositories):
repositories{ flatDir{ dirs 'libs' //就是你放aar的目录地址 } }
第三步:build.gradle里面添加依赖(dependencies ):
//你的其他依赖 compile(name: 'SMSSDK-3.0.0', ext: 'aar') compile(name: 'SMSSDKGUI-3.0.0', ext: 'aar')
第四步:配置AndroidManifest.xml
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" />
2添加以下Activity:
<activity android:name="com.mob.tools.MobUIShell" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:windowSoftInputMode="stateHidden|adjustResize" />
3在Application节点下添加以下属性:
android:name="com.mob.MobApplication"
4在Application节点下添加以下meta-data:
<meta-data android:name="Mob-AppKey" android:value="221607712f160" /> <meta-data android:name="Mob-AppSecret" android:value="0f6ddf18f8f69bbb3fa8f1b29967c138" />
别忘了去http://wiki.mob.com/sdk-sms-android-3-0-0/获取AppkeyheAppSecret
5代码混淆:
# SMSSDK -dontwarn com.mob.** -keep class com.mob.**{*;} -dontwarn cn.smssdk.** -keep class cn.smssdk.**{*;}
第五步:在你的主Activity的onCreate方法中添加以下代码以完成sdk的注册:
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private EditText dianhua; private EditText yanzhengma; private Button but1; private Button but2; private EventHandler eventHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); // 如果希望在读取通信录的时候提示用户,可以添加下面的代码,并且必须在其他代码调用之前,否则不起作用;如果没这个需求,可以不加这行代码 // SMSSDK.setAskPermisionOnReadContact(boolShowInDialog) // 创建EventHandler对象 eventHandler = new EventHandler() { public void afterEvent(int event, int result, Object data) { if (data instanceof Throwable) { Throwable throwable = (Throwable)data; final String msg = throwable.getMessage(); Log.i("login",msg+"------"); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); } }); } else { if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) { } else if(event==SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE){ Log.i("login","验证成功"); Intent intent = new Intent(MainActivity.this,Main2Activity.class); startActivity(intent); } } } }; // 注册监听器 SMSSDK.registerEventHandler(eventHandler); } //在onDestroy中注销SDK protected void onDestroy() { super.onDestroy(); SMSSDK.unregisterEventHandler(eventHandler); } private void initView() { dianhua = (EditText) findViewById(R.id.dianhua); yanzhengma = (EditText) findViewById(R.id.yanzhengma); but1 = (Button) findViewById(R.id.but1); but2 = (Button) findViewById(R.id.but2); but1.setOnClickListener(this); but2.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.but1: SMSSDK.getVerificationCode("86", dianhua.getText().toString()); break; case R.id.but2: SMSSDK.submitVerificationCode("86",dianhua.getText().toString(),yanzhengma.getText().toString()); break; } }