最近模仿黑马的手机卫士做了听久了,想想得把做的时候出现的问题记录下菜好用。
做到黑白名单测试的时候,短信炸了, abortBroadcast()在4.4以后都不会有效果了,也去找了很久,有说从数据库删除的,反正我都试过,没卵用。这次主要记录下拦截电话的。我是使用android studio3.0的版本,在导入NeighboringCellInfo和ITelephony时候问题比较大,在导入成功后,build就可以使用了。贴图示意。

以下是我的源代码,初学android,多多指点。

class MyPhoneStateListener extends PhoneStateListener {@Overridepublic void onCallStateChanged(int state, String incomingNumber) {switch (state) {case TelephonyManager.CALL_STATE_IDLE://空闲状态break;case TelephonyManager.CALL_STATE_OFFHOOK://挂掉电话状态break;case TelephonyManager.CALL_STATE_RINGING://响铃,显示吐司endCall(incomingNumber);break;}super.onCallStateChanged(state, incomingNumber);}}

下面这段被我注释的是视频中的代码,没有效果,我自己又查找了一份,主要用到了反射机制,mode是获取的类型,2是电话,3是电话加短信。

public void endCall(String phone){int mode = dao.getMode(phone);if (mode ==2 || mode ==3){try {/*  //1 获取ServiceManager字节码文件Class<?> clazz = Class.forName("android.os.ServiceManager");//2.获取方法Method method = clazz.getMethod("getService",String.class);//3.反射调用此方法IBinder iBinder = (IBinder) method.invoke(null,Context.TELECOM_SERVICE);//4.调用获取aidl文件对象方法ITelephony iTelephony = ITelephony.Stub.asInterface(iBinder);//5.调用aidl中隐藏的endcalliTelephony.endCall();*/Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);// 获取远程TELEPHONY_SERVICE的IBinder对象的代理IBinder binder = (IBinder) method.invoke(null, new Object[] { "phone" });// 将IBinder对象的代理转换为ITelephony对象ITelephony telephony = ITelephony.Stub.asInterface(binder);// 挂断电话telephony.endCall();} catch (Exception e) {e.printStackTrace();}}}

NeighboringCellInfo

package android.telephony;parcelable NeighboringCellInfo;

ITelephony(似乎只用到了endCall)

/** Copyright (C) 2007 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.android.internal.telephony;import android.os.Bundle;
import java.util.List;
import android.telephony.NeighboringCellInfo;/*** Interface used to interact with the phone.  Mostly this is used by the* TelephonyManager class.  A few places are still using this directly.* Please clean them up if possible and use TelephonyManager insteadl.** {@hide}*/
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();
}

android短信和电话拦截相关推荐

  1. android 短信接口收拦截,给手机装“来点黑名单” 拒绝垃圾短信和电话

    给手机装个"来电黑名单" 有了手机之后,不自觉就被卷入信息漩涡中间.面对排山倒海的垃圾短信和骚扰电话,我们如何能拒绝?或者是"礼貌地拒绝"?其实,对于类似QQ. ...

  2. android 自动读取短息,Android实现短信验证码自动拦截读取功能

    本文实例为大家分享了Android短信验证码自动拦截读取 的具体代码,供大家参考,具体内容如下 知识准备: 1.观察者模式的理解[文章稍后来到~~] 2.Android的Cursor使用[Androi ...

  3. Android项目:手机安全卫士(12)—— 通讯卫士之电话短信黑名单设置与拦截

    版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Android项目:手机安全卫士(12)-- 通讯卫士之电话.短信黑名单设置与拦截 1 介绍 今天进入新的功能开发了:通讯卫士, ...

  4. Android系统开发:短信的号码拦截

    Android系统开发:短信的号码拦截 Code:Android源码 功能要求:针对某号码,短信的接收与发送的监听与拦截. 设备对该号码发送短信的拦截 实现思路 : 应用发送短信(无论是否是默认短信) ...

  5. 关于Android短信拦截

           今天参加了培训公司筹划的面试,主要是关于安卓客户端的技术面试,总结这次面试我决定写一些总结,首先就是关于我所写的手机通讯录的短信拦截功能的介绍:手机在接收到短信后会发出一段广播,我们只需 ...

  6. Android短信拦截机制适配的坑(下)--4.4以上系统,主要是6.0

    前一篇文章,Android短信拦截机制适配的坑(上)--4.4以下系统 介绍了广播接收的顺序,但是我明确说明在4.4以下系统,那么4.4及以上系统会遇到说明问题呢? 首先我们要来了解4.4系统短信的机 ...

  7. Android 短信拦截及用途分析

    监听系统短信这个只能作为一个技术点来研究下,读者可能在工作中可能不会哦涉及到,一般的应用软件也不会有这个需求 但是作为程序员呢,多了解一下也是好的. Android 监听系统短信有什么用? 1.对系统 ...

  8. Auto.js 调用系统短信、电话

    本文所有教程及源码.软件仅为技术研究.不涉及计算机信息系统功能的删除.修改.增加.干扰,更不会影响计算机信息系统的正常运行.不得将代码用于非法用途,如侵立删! Auto.js 调用系统短信.电话 操作 ...

  9. WCF 实例 —— Android 短信助手 (WCF + Android)

    (1)最近开始学习 Android,为了更快上手于是给自己找个小课题来练习一下: WCF作为服务端开放RESTful Service,Android作为客户端将手机上的短信传给服务端显示,并轮询服务端 ...

最新文章

  1. python 正则表达式 前瞻_正则表达式 For Python
  2. 一文梳理缺陷检测方法
  3. mysql查询不到邮件_mysql – sql查询通过电子邮件获取用户列表
  4. 笔记1-3: 从标准输入读取命令并执行
  5. html前端登录验证码,前端登录页面开发_js生成验证码并验证
  6. 关于fflush(stderr);
  7. 经典算法复现!(条件随机场)CRF原理及实现代码
  8. 2020蓝桥杯省赛---java---B---5(排序)
  9. python3中的int类型占64位,有没有什么办法来强制Python来使用64位整数的Windows?
  10. python爬虫:读取PDF
  11. Intra Chroma Prediction
  12. C语言之字符串探究(十):递归逆置字符串
  13. 动手学深度学习Pytorch Task04
  14. 【服务器】【阿里云】免费升级HTTP为HTTPS
  15. 第三章 垃圾回收的一些概念
  16. 10 个 Python 项目简单又超有趣
  17. Python之XML模块
  18. 【进大厂必学】3W字180张图学习Linux基础总结
  19. 微信小程序中英文切换
  20. Win10如何玩Win7自带的游戏

热门文章

  1. 世界上最高效的笔记方法(改变你那老版的记笔记方法吧)
  2. 如何清除img图片下面有一片空白
  3. F12 console的用法,以及如何debug程序?
  4. 企业级应用与互联网应用
  5. ubuntu启动程序报错
  6. LeetCode 1240. 铺瓷砖(深搜剪枝)
  7. android:给图片打水印
  8. html的相对位置和绝对位置的理解,搭配float使用。
  9. oppo find x3和x3pro外观区别 oppo find x3和x3pro参数对比哪个性价比高
  10. 在Proxmox VE中设置硬件资源在虚拟机中直通