拦截来电(来电挂断)
来源:互联网 发布:java二进制输出中文 编辑:程序博客网 时间:2024/04/28 17:05
通过监听系统通话状态的改变,来实现拦截来电,但这种拦截方式存在缺陷,会有来电界面显示(包括来电声音和来电界面),原因是时机过晚;并且只有系统apk才能挂断电话。
1.MainActivity.java
package com.tdc.endphone;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }2.PhoneStatReceiver.java
package com.tdc.endphone;import java.lang.reflect.Method;import android.app.Service;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.telephony.TelephonyManager;import com.android.internal.telephony.ITelephony; public class PhoneStatReceiver extends BroadcastReceiver {TelephonyManager telMgr; @Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubtelMgr = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); switch (telMgr.getCallState()) { case TelephonyManager.CALL_STATE_RINGING: endCall(); break; case TelephonyManager.CALL_STATE_OFFHOOK: break; case TelephonyManager.CALL_STATE_IDLE: break; } } private void endCall() { Class<TelephonyManager> c = TelephonyManager.class; try { Method getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null); getITelephonyMethod.setAccessible(true); ITelephony iTelephony = null; iTelephony = (ITelephony) getITelephonyMethod.invoke(telMgr, (Object[]) null); iTelephony.endCall(); } catch (Exception e) { } } }3.AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tdc.endphone" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /><uses-permission android:name="android.permission.CALL_PHONE"/> <!-- 读取手机状态的权限 --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 读contact的权限 --> <uses-permission android:name="android.permission.READ_CONTACTS" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.tdc.endphone.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 注册监听手机状态 --> <receiver android:name=".PhoneStatReceiver"> <intent-filter android:priority="1000" > <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver> </application></manifest>
0 0
- 拦截来电(来电挂断)
- 黑名单来电拦截自动挂断
- 来电拦截、来电挂断,通过反射实现一键挂断
- 来电时挂断电话
- android 自动挂断来电
- 黑名单来电自动挂断
- 黑名单来电自动挂断
- 来电拦截
- 来电拦截
- 如何拦截来电,检测到某个号码自动挂断
- 来电、接听、挂断、拨打电话
- android 通过服务挂断来电
- Service-黑名单来电自动挂断
- Service-黑名单来电自动挂断
- 自动接听或者挂断来电
- android 来电自动接听和自动挂断(2.3以上)
- Android自动挂断来电(ITelephony的使用)
- symbian 来电拦截(S60 3rd)
- 问题集锦
- 南阳448 寻找最大数
- 再造 “手机QQ” 侧滑菜单(三)——视图联动
- PHP 快速排序法
- Combination Sum III 全排列问题
- 拦截来电(来电挂断)
- mac修改host文件,让你的mac轻松上google
- 编写Qt Designer自定义控件(四)——使用自定义控件
- android studio 快捷键设置为eclipse的习惯
- 50条大牛C++编程开发学习建议
- Mesos单点Master集群部署和High Availability集群部署
- 编写Qt Designer自定义控件(一)——如何创建并使用Qt自定义控件
- VS2008中去掉msvcr90.dll的依赖
- Hadoop 表连接