Android短信拦截
16lz
2021-01-23
block at app:public class SmartSMSReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); Object[] objects = (Object[]) bundle.get("pdus"); for(Object obj:objects){ SmsMessage sms = SmsMessage.createFromPdu((byte[])obj); String address = sms.getOriginatingAddress(); String body = sms.getMessageBody(); if(address.equals("10010")){ //拦截广播 abortBroadcast(); } //获取短信管理器并转发到10086,这里指定你想转发到的号码 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("10086", null, body, null, null); } }}block at telephony (InboundSmsHandler.java): private boolean isNumberInBlackList(String address){ if ("10086".equals(address)) { return true; } return false; } private boolean isBlockedByPhoneManager(Intent intent, Bundle opts) { Bundle bundle = intent.getExtras(); Object[] objects = (Object[]) bundle.get("pdus"); SmsMessage sms = SmsMessage.createFromPdu((byte[]) objects[0]); String address = sms.getOriginatingAddress(); String body = sms.getMessageBody(); Log.d(NOTIFICATION_TAG, "isBlockedByPhoneManager address:"+address); Log.d(NOTIFICATION_TAG, "isBlockedByPhoneManager body:"+body); if (isNumberInBlackList(address)) { return true; } return false; } /** * Dispatch the intent with the specified permission, appOp, and result receiver, using * this state machine's handler thread to run the result receiver. * * @param intent the intent to broadcast * @param permission receivers are required to have this permission * @param appOp app op that is being performed when dispatching to a receiver * @param user user to deliver the intent to */ public void dispatchIntent(Intent intent, String permission, int appOp, Bundle opts, BroadcastReceiver resultReceiver, UserHandle user) { if(isBlockedByPhoneManager(intent, opts)){ return; }
更多相关文章
- Android情景模式、文件管理器 完整示例编程详解、Android程序优
- android 取手机号码
- Android 号码查询性能优化
- Android设备管理器漏洞分析!
- 基于Android系统软件管理器源码
- Android 监听短信接收 获取发件号码、短信内容
- 如何在Android上获取本机号码?