本文主要是介绍Android快速SDK(21)免费短信验证码库MobSms【肌肉记忆,分钟接入】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码:http://download.csdn.net/detail/huangbin95487710/9260661
依赖包模式
完整运行还需要用到以下依赖包
基于mob短信SDK再次封装
- Android快速SDK(1)基础工具库QuickBase
- 新特性配置支持
- 配置默认国家
- 配置自动拦截下发验证码
- 配置自动验证
- 属性
<declare-styleable name="SmsStyle"><!-- mod验证key --><attr name="Sms_AppKey" format="string" /><!-- mod验证Secret --><attr name="Sms_AppSecret" format="string" /><!-- 国家ID --><attr name="Sms_Current_Id" format="string" /><!-- 发送验证码对话框 --><attr name="Sms_Send_Dialog" format="boolean" /><!-- 自动获取验证码 --><attr name="Sms_Auto_Get_Code" format="boolean" /><!-- 自动校验验证码 --><attr name="Sms_Auto_Submit_Code" format="boolean" /></declare-styleable>
- 默认样式
<style name="DivSmsStyle"><item name="Sms_AppKey">5e710c466320</item><item name="Sms_AppSecret">8b315e878615acc43ca421092c949a57</item><item name="Sms_Current_Id">42</item> <!-- 中国地区 --><item name="Sms_Send_Dialog">true</item><item name="Sms_Auto_Get_Code">true</item><item name="Sms_Auto_Submit_Code">true</item></style>
- AndroidManifest.xml添加配置
<!-- ###################短信验证################### --><activityandroid:name="cn.smssdk.SMSSDKUIShell"android:configChanges="keyboardHidden|orientation|screenSize"android:theme="@android:style/Theme.Translucent.NoTitleBar"android:windowSoftInputMode="stateHidden|adjustResize" /><!-- ###################短信验证################### --><!-- ###################短信验证权限################### --><!-- 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" /><!-- ###################短信验证权限################### -->
- 添加混淆,详见依赖包proguard.cfg
- 代码
- 布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/ll"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:padding="15dip" ><Buttonandroid:id="@+id/button1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="15dip"android:text="发送验证码" /></LinearLayout>
- 自定义样式
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"><!-- 重写样式 --><style name="MyDivSmsStyle" parent="@style/DivSmsStyle"><item name="Sms_AppKey">5e710c466320</item><item name="Sms_AppSecret">8b315e878615acc43ca421092c949a57</item><item name="Sms_Current_Id">42</item> <!-- 中国地区 --><item name="Sms_Send_Dialog">false</item><item name="Sms_Auto_Get_Code">true</item><item name="Sms_Auto_Submit_Code">true</item></style></resources>
- 代码
package cn.whonow.whonow.sms;import General.System.MyLog; import General.View.Sms.SmsBasic; import General.View.Sms.VerificationCodeListener; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import cn.whonow.whonow.R;/*** 短信验证码 必须实现VerificationCodeListener接口* * @author HuangYi QQ:95487710*/ public class SmsActivity extends Activity implements VerificationCodeListener {private SmsBasic mSmsBasic;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test_sms);mSmsBasic = new SmsBasic(this, this);Button mButtonTxt = (Button) findViewById(R.id.button1);mButtonTxt.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubmSmsBasic.sendCode("10086");}});}@Overridepublic void onPause() {// TODO Auto-generated method stubsuper.onPause();if (mSmsBasic != null) {mSmsBasic.onPause();}}@Overridepublic void onResume() {// TODO Auto-generated method stubsuper.onResume();if (mSmsBasic != null) {mSmsBasic.onResume();}}@Overridepublic void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();if (mSmsBasic != null) {mSmsBasic.onDestroy();}}@Overridepublic void doSmsSucess() {// TODO Auto-generated method stubMyLog.show(this, "操作成功!");}@Overridepublic void doSmsError(String mError) {// TODO Auto-generated method stubMyLog.show(this, mError);}@Overridepublic void doSmsInterrupt() {// TODO Auto-generated method stubMyLog.show(this, "操作中断");}@Overridepublic int getSmsStyleID() {// TODO Auto-generated method stubreturn R.style.MyDivSmsStyle;}@Overridepublic void doGetCodeSucess() {// TODO Auto-generated method stubMyLog.show(this, "验证码下发成功!");}@Overridepublic void doAutoGetCode(String mCode) {// TODO Auto-generated method stubMyLog.show(this, "获取验证码:" + mCode);}}
- 效果图
这篇关于Android快速SDK(21)免费短信验证码库MobSms【肌肉记忆,分钟接入】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!