Android之——拦截外拨电话
2015-07-21 23:19
549 查看
转载请注明出处:/article/8380808.html
这里,向大家简单介绍通过BroadcastReceiver来拦截外拨电话的方法。
1、创建PhoneReceiver继承自BroadcastReceiver
这个类是BroadcastReceiver的子类,具体的拦截操作在这个类中实现,我在这里只是简单的介绍一下方法,把获取到的外拨号码打印出来。具体的业务逻辑就要大家自己去实现了。具体代码如下:
package com.lyz.rereiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; /** * 拦截拨出电话 * @author liuyazhuang * */ public class PhoneReceiver extends BroadcastReceiver { private static final String TAG = "PhoneReceiver"; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String num = getResultData(); Log.i(TAG, num); } }
2、在AndroidManifest.xml文件中要注册相应的授权信息
具体实现如下:<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lyz.phone" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <!-- 拦截外拨通话授权 --> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.lyz.phone.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="com.lyz.rereiver.PhoneReceiver"> <intent-filter android:priority="1000"> <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> </intent-filter> </receiver> </application> </manifest>大功告成,是不是很简单呢?
温馨提示:大家可以到http://download.csdn.net/detail/l1028386804/8921101链接下载完整的示例代码
相关文章推荐
- Android(java)学习笔记86:案例短信发送器
- This Handler class should be static or leaks might occur Android警告处理
- android locationManager定位
- android动画模块 Tween 动画的实现原理 详解
- [Android] Service服务详解以及如何使service服务不被杀死
- Android socket在系统休眠情况下调研
- android ndk开发hello world入门
- Android 判断字符串是否是身份证、邮箱、银行卡、手机号、中文
- Android总结之PopupWindow
- Android Studio下配置AndroidAnnotation
- Android中添加水平线和垂直线
- Multi-threading Model: My Interesting Part in Android
- [Android] How to use github with android studio
- Android Service的用法
- android守护进程
- android守护进程
- android守护进程
- Android自定义弹窗效果
- Android 编程下 Touch 事件的分发和消费机制
- ListView优化总结(一)--Android