wemall app商城源码Android短信监听接收器


发布者 wemallshop  发布时间 1480147658213
关键字 分享 

wemall doraemon是Android客户端程序,服务端采用wemall微信商城,不对原商城做任何修改,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可随意定制修改。本文分享其中短信监听接收器,用于自动获取短信验证码,然后自动填写到验证码区域代码,供技术员参考学习。


package cn.smssdk.gui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import cn.smssdk.SMSSDK;
/** 短信监听接收器,用于自动获取短信验证码,然后自动填写到验证码区域*/
public class SMSReceiver extends BroadcastReceiver {

	private static final String ACTION_SMS_RECEIVER = "android.provider.Telephony.SMS_RECEIVED";

	private SMSSDK.VerifyCodeReadListener listener;
	public SMSReceiver(SMSSDK.VerifyCodeReadListener verifyCodeReadListener) {
		this.listener = verifyCodeReadListener;
	}


	/**
	 * 不要使用AndroidManifest.xml配置的方式注册Receiver,
	 * 请使用Context.registerReceiver注册监听器, 因为初始化的时候要传入监听器
	 */
	public SMSReceiver() {
		String msg = "Please dynamically register an instance of this class with Context.registerReceiver."
				+"\r\nIf not, the SMSSDK.VerifyCodeReadListener will be null!";
		Log.w("cn.smssdk.gui.SMSReceiver", msg);
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		if(ACTION_SMS_RECEIVER.equals(intent.getAction())) {
			Bundle bundle = intent.getExtras();
			if(bundle != null) {
                Object[] pdus = (Object[]) bundle.get("pdus");
                SmsMessage[] smsArr = new SmsMessage[pdus.length];
                for (int i = 0; i < pdus.length; i++) {
                	smsArr[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
				}

                for (SmsMessage sms: smsArr) {
                	if(sms != null) {
                		SMSSDK.readVerificationCode(sms, listener);
                	}
				}
			}// END if(bundle != null)
		}
	}
}

 原文详情地址:http://Git.oschina.NET/zzunet/wemall-doraemon/commit/e8f303df5663dc69fe47bb9623222149d40e3956

wemall doraemonAndroid app商城详情地址:http://www.koahub.com/home/product/55

wemall官网地址:http://www.wemallshop.com

wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统

wemall









  开源的 OurJS
OurJS开源博客已经迁移到 OnceOA 平台。

  关注我们
扫一扫即可关注我们:
OnceJS

OnceOA