Android之电话拦截
今天来和大家一起分享一下我最近写的一个Demo,类似于黑名单访问,也就是我们俗称的电话拦截
首先我们需要两个aidl文件
第一个:NeighboringCellInfo.aidl
package android.telephony;parcelable NeighboringCellInfo;
第二个:ITelephony.aidl
package com.android.internal.telephony;import android.os.Bundle;
import java.util.List;
import android.telephony.NeighboringCellInfo;interface ITelephony { /*** Dial a number. This doesn't place the call. It displays* the Dialer screen.* @param number the number to be dialed. If null, this* would display the Dialer screen with no number pre-filled.*/void dial(String number);/*** Place a call to the specified number.* @param number the number to be called.*/void call(String number);/*** If there is currently a call in progress, show the call screen.* The DTMF dialpad may or may not be visible initially, depending on* whether it was up when the user last exited the InCallScreen.** @return true if the call screen was shown.*/boolean showCallScreen();/*** Variation of showCallScreen() that also specifies whether the* DTMF dialpad should be initially visible when the InCallScreen* comes up.** @param showDialpad if true, make the dialpad visible initially,* otherwise hide the dialpad initially.* @return true if the call screen was shown.** @see showCallScreen*/boolean showCallScreenWithDialpad(boolean showDialpad);/*** End call or go to the Home screen** @return whether it hung up*/boolean endCall();/*** Answer the currently-ringing call.** If there's already a current active call, that call will be* automatically put on hold. If both lines are currently in use, the* current active call will be ended.** TODO: provide a flag to let the caller specify what policy to use* if both lines are in use. (The current behavior is hardwired to* "answer incoming, end ongoing", which is how the CALL button* is specced to behave.)** TODO: this should be a oneway call (especially since it's called* directly from the key queue thread).*/void answerRingingCall();/*** Silence the ringer if an incoming call is currently ringing.* (If vibrating, stop the vibrator also.)** It's safe to call this if the ringer has already been silenced, or* even if there's no incoming call. (If so, this method will do nothing.)** TODO: this should be a oneway call too (see above).* (Actually *all* the methods here that return void can* probably be oneway.)*/void silenceRinger();/*** Check if we are in either an active or holding call* @return true if the phone state is OFFHOOK.*/boolean isOffhook();/*** Check if an incoming phone call is ringing or call waiting.* @return true if the phone state is RINGING.*/boolean isRinging();/*** Check if the phone is idle.* @return true if the phone state is IDLE.*/boolean isIdle();/*** Check to see if the radio is on or not.* @return returns true if the radio is on.*/boolean isRadioOn();/*** Check if the SIM pin lock is enabled.* @return true if the SIM pin lock is enabled.*/boolean isSimPinEnabled();/*** Cancels the missed calls notification.*/void cancelMissedCallsNotification();/*** Supply a pin to unlock the SIM. Blocks until a result is determined.* @param pin The pin to check.* @return whether the operation was a success.*/boolean supplyPin(String pin);/*** Handles PIN MMI commands (PIN/PIN2/PUK/PUK2), which are initiated* without SEND (so <code>dial</code> is not appropriate).** @param dialString the MMI command to be executed.* @return true if MMI command is executed.*/boolean handlePinMmi(String dialString);/*** Toggles the radio on or off.*/void toggleRadioOnOff();/*** Set the radio to on or off*/boolean setRadio(boolean turnOn);/*** Request to update location information in service state*/void updateServiceLocation();/*** Enable location update notifications.*/void enableLocationUpdates();/*** Disable location update notifications.*/void disableLocationUpdates();/*** Enable a specific APN type.*/int enableApnType(String type);/*** Disable a specific APN type.*/int disableApnType(String type);/*** Allow mobile data connections.*/boolean enableDataConnectivity();/*** Disallow mobile data connections.*/boolean disableDataConnectivity();/*** Report whether data connectivity is possible.*/boolean isDataConnectivityPossible();Bundle getCellLocation();/*** Returns the neighboring cell information of the device.*/List<NeighboringCellInfo> getNeighboringCellInfo();int getCallState();int getDataActivity();int getDataState();/*** Returns the current active phone type as integer.* Returns TelephonyManager.PHONE_TYPE_CDMA if RILConstants.CDMA_PHONE* and TelephonyManager.PHONE_TYPE_GSM if RILConstants.GSM_PHONE*/int getActivePhoneType();/*** Returns the CDMA ERI icon index to display*/int getCdmaEriIconIndex();/*** Returns the CDMA ERI icon mode,* 0 - ON* 1 - FLASHING*/int getCdmaEriIconMode();/*** Returns the CDMA ERI text,*/String getCdmaEriText();/*** Returns true if CDMA provisioning needs to run.*/boolean getCdmaNeedsProvisioning();/*** Returns the unread count of voicemails*/int getVoiceMessageCount();/*** Returns the network type*/int getNetworkType();/*** Return true if an ICC card is present*/boolean hasIccCard();
}
将这两个aidl文件copy进去之后,我们再来新建一个activity,并且让他继承 BroadcastReceiver这个类
代码如下:
public class MyPhoneStateReceived extends BroadcastReceiver {@Override
public void onReceive(Context context, Intent intent) {if("android.intent.action.PHONE_STATE".equals(intent.getAction())){//得到电话管理者TelephonyManager telephonyManager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);//得到电话的状态int state=telephonyManager.getCallState();switch (state) {case TelephonyManager.CALL_STATE_RINGING:break;case TelephonyManager.CALL_STATE_OFFHOOK:Log.i("test","通话中...录音中");break;case TelephonyManager.CALL_STATE_IDLE:Log.i("test","挂了");break;}//得到电话号码String number=intent.getStringExtra("incoming_number");Log.i("test","来电了"+number);//得到电话管理者类对象Class<TelephonyManager> clazz=TelephonyManager.class;//得到方法try {Method method=clazz.getDeclaredMethod("getITelephony",null);//设置可访问method.setAccessible(true);//执行方法ITelephony iTelephony= (ITelephony) method.invoke(telephonyManager,null);//判断Log.i("tt","我拦截的号码!!!"+number);if("xxxxxx".equals(number)){Log.i("tt","是我拦截的号码!!!");iTelephony.endCall();}} catch (NoSuchMethodException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (RemoteException e) {e.printStackTrace();}}
}
}
xxxxxx里面填你们想要拦截的电话号码就可以了,这样,电话拦截就做好了
Android之电话拦截相关推荐
- Android中电话拦截器案例
实验要求:实现拦截保存到手机中的号码 1.在main-activity布局文件中代码如下: <?xml version="1.0" encoding="utf-8& ...
- 广播接收者android,电话拦截广播,电话接收者demo
一.Android广播机制介绍 广播机制最大的特点就是发送方并不关心接收方是否接到数据,也不关心接收方是如何处理数据的. Android中广播的是操作系统中产生的各种各样的事件.例如,收到一条短信就会 ...
- Android电话拦截及拦截提示音的实现
本文所讲的内容是在Android系统中如何写程序进行 电话拦截,并发出拦截提示音提醒用户,可以说此功能还是比较实用的. 1.电话拦截 这个功能大家可能都知道了,就是利用反射原理调用ITelephony ...
- Android手机安全软件之电话拦截功能浅析
目前中国市场,骚扰电话大量的充斥手机用户的生活,因此手机安全软件的电话拦截功能受到广泛关注和使用.但第三方应用级电话拦截功能的效果并不理想,比如拦截电话时已经响了一声.或出现短暂的来电界面,多款安全软 ...
- android 原生分享界面_原生 Android 用户终于能用上骚扰电话拦截了
虽然对大部分国产手机用户而言,骚扰电话早已不再是一个令人头痛的问题.但如果你使用的是原生/类原生 Android 系统(例如 Google Pixel),骚扰电话拦截这件事就变得非常棘手了.所以和很多 ...
- Android开发之骚扰电话,谷歌发布了Android 11 第二个版本 还增加了一个强化骚扰电话拦截的API...
3月19日消息,据国外媒体报道,在发布Android 11的第一个开发者预览版几乎整整一个月之后,谷歌发布了第二个版本.Android 11 DP2是一个开发者预览版,不是公测版本,因此不包含人们所期 ...
- Android开发——短信电话拦截/接听电话
1.短信拦截 首先需要声明的是,Android4.4版本以上,如果想做到短信拦截,必须成为default sms,把所有短信相关的功能都包揽了,然后再做短信拦截.但这种做法,适配性和兼容性的工作是非常 ...
- Android项目:手机安全卫士(13)—— 通讯卫士之电话拦截与挂断
Android项目:手机安全卫士(13)-- 通讯卫士之电话拦截与挂断 1 介绍 上一节我们讲了黑名单数据的存储等 CRUD 操作,今天,就到了它们发挥作用的时候了,通讯卫士功法终于要练成了.我们实现 ...
- android电话拦截软件下载,骚扰电话拦截器
骚扰电话拦截器是一款支持自定义数据库的电话拦截软件,你可以自定义的在上面倒入各种骚扰电话的数据或者是API,这款软件会通过这些API来帮助你进行拦截,小巧的体积以及轻松的操作方式非常适合那些需要高颜D ...
最新文章
- IANA定义的常见服务的端口号列表
- JAVA自学笔记24
- 如何取消JS事件的派发——stopPropagation()
- 火的不要不要的公有云和私有云都是什么鬼?
- 开了gomod不识别gopath_三分钟掌握Go mod常用与高级操作
- 高清音质背后:网易云信音乐教学方案技术解密
- python 获取当天和前几天时间数据(亲测)
- git mergetool 解决冲突的问题
- 分享微软官方Demo用的SharePoint 2010, Exchange 2010, Lync 2010虚拟机
- 简单数字电压表的c语言程序,简易数字直流电压表电路及程序
- 计算机考研408每日一题 day157
- 联想计算机型号吧,lenovo全系列联想笔记本电脑型号对照表
- 80后的我,记忆里和吃有关的那些事
- php怎么做倒计时活动,PHP实现倒计时功能
- 华为 GaussDB 数据库十问
- 康耐视VisionPro
- 【MicroPython ESP32】ssd1306驱动0.96“I2C屏幕cube3D图形显示
- 思路如此简单的购买水果问题
- Discuz论坛 创始人密码忘记解决办法!
- Linux与Android安全差异
热门文章
- 【高端论坛】王家耀院士:大变化时代的地图科学(全文PPT分享)
- 邢台技师学院计算机系,世赛中国队选手介绍邢台技师学院学生杜润
- 电梯演讲展示产品优势特点
- DM8168 IPNC Boa移植
- 【汇编实战开发笔记】从汇编代码中找出一段普通的for循环变成“死循环”的根本原因(RT-Thread技术论坛优秀文章)
- 虚拟机为什么连接不上网络,怎样才能连上网络
- matlab腔内光子寿命,光子在腔内的平均寿命
- 陈皓:谈谈数据安全和云存储
- 中国的市场营销部到底是怎么分工的,每个人到底在干什么事?
- 「Pygame经典合集」​​​​​​终极 大招:让你玩儿到爽