Android 短信驗(yàn)證碼自動(dòng)填寫
成都創(chuàng)新互聯(lián)成立10多年來,這條路我們正越走越好,積累了技術(shù)與客戶資源,形成了良好的口碑。為客戶提供成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、空間域名、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。網(wǎng)站是否美觀、功能強(qiáng)大、用戶體驗(yàn)好、性價(jià)比高、打開快等等,這些對(duì)于網(wǎng)站建設(shè)都非常重要,成都創(chuàng)新互聯(lián)通過對(duì)建站技術(shù)性的掌握、對(duì)創(chuàng)意設(shè)計(jì)的研究為客戶提供一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。
1.自定義Observer監(jiān)聽短信數(shù)據(jù)庫變化(注意添加短信權(quán)限)
import android.app.Activity; import android.content.ContentResolver; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Handler; import android.text.TextUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by 001 on 17/3/22. */ public class SmsObserver extends ContentObserver { public static final String SMS_URI_INBOX = "content://sms/inbox"; private Activity activity = null; private String smsContent = ""; private SmsListener listener; public SmsObserver(Activity activity, Handler handler, SmsListener listener) { super(handler); this.activity = activity; this.listener = listener; } @Override public void onChange(boolean selfChange) { super.onChange(selfChange); Cursor cursor = null; // 讀取收件箱中含有某關(guān)鍵詞的短信 ContentResolver contentResolver = activity.getContentResolver(); cursor = contentResolver.query(Uri.parse(SMS_URI_INBOX), new String[] { "_id", "address", "body", "read" }, "body like ? and read=?", new String[] { "%關(guān)鍵詞%", "0" }, "date desc"); if (cursor != null) { cursor.moveToFirst(); if (cursor.moveToFirst()) { String smsbody = cursor .getString(cursor.getColumnIndex("body")); String regEx = "[^0-9]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(smsbody.toString()); smsContent = m.replaceAll("").trim().toString(); if (!TextUtils.isEmpty(smsContent)) { listener.onResult(smsContent); } } } } /* * 短信回調(diào)接口 */ public interface SmsListener { /** * 接受sms狀態(tài) * * @Title: onResult */ void onResult(String smsContent); } }
2.使用:
SmsObserver smsObserver = new SmsObserver(this, new Handler(), new SmsObserver.SmsListener() { @Override public void onResult(String smsContent) { //根據(jù)需求寫 //如:editText.setText(smsContent); } });this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, smsObserver);
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
網(wǎng)站題目:Android短信驗(yàn)證碼自動(dòng)填寫
路徑分享:http://aaarwkj.com/article32/isjppc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、全網(wǎng)營銷推廣、Google、微信小程序、關(guān)鍵詞優(yōu)化、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)