Android之类似于黑名单的短信拦截

如果没有拦截的话 也不要慌 对于有些手机是没有用的,所以这种去了解玩玩就可以了

 
直接上代码:
xml权限配置:
 
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zking.laci.android22_broacast"> <!--接收广播的权限--> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MySMSReceiver"> <intent-filter android:priority="1000" > <action android:name="android.provider.Telephony.SMS_RECEIVED"></action> </intent-filter> </receiver> </application> </manifest>

 

 

java代码:记得新创个类

 

 

 
package com.zking.laci.android22_broacast; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.util.Log; /** * Created by Laci on 2017/7/13. */ public class MySMSReceiver extends BroadcastReceiver{ private String a; @Override public void onReceive(Context context, Intent intent) { if("android.provider.Telephony.SMS_RECEIVED".equals(intent.getAction())){ Log.i("test","来了"); //得到短信的内容 Bundle bundle=intent.getExtras(); Object[] o= (Object[]) bundle.get("pdus"); //实例化SmsMessage SmsMessage smsMessage[]=new SmsMessage[o.length]; //把o里面的数据传递给smsMessage for (int i = 0; i < o.length; i++) { smsMessage[i]=SmsMessage.createFromPdu((byte[]) o[i]); } for (SmsMessage message : smsMessage) { a = message.getDisplayOriginatingAddress(); Log.i("test","短信发送者"+message.getDisplayOriginatingAddress()+":"+message.getDisplayMessageBody()); } //如果有例如下方的电话时就直接拦截,如果没有拦截的话 也不要慌 对于有些手机是没有用的,所以这种去玩玩就可以了 if("+86187xxxxxxxxxx4".equals(a)){ abortBroadcast(); //内容提供者 //删除系统收短信的数据库表 Log.i("test","拦截不了"); } } } } 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值