android外拨电话拦截器,完整源码
1.配置清单文件
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="cn.caicai.smslistener" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk android:minSdkVersion="8" /> 8 <uses-permission android:name="android.permission.RECEIVE_SMS"/> 9 <uses-permission android:name="android.permission.INTERNET"/> 10 <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> 11 <application 12 android:icon="@drawable/ic_launcher" 13 android:label="@string/app_name" > 14 <receiver android:name=".phpbroadcastreceive" > 15 <intent-filter android:priority="1000"> 16 <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 17 </intent-filter> 18 </receiver> 19 </application> 20 21 </manifest>
注意必须添加权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
2.创建拨号拦截器即广播接收者
1 package cn.caicai.smslistener; 2 3 import android.content.BroadcastReceiver; 4 import android.content.Context; 5 import android.content.Intent; 6 7 public class phpbroadcastreceive extends BroadcastReceiver { 8 9 @Override 10 public void onReceive(Context context, Intent intent) { 11 String num=getResultData();//获取外拨电话号码 12 if("15555215556".equals(num)){//如果为15555215556,将外拨号设为空,阻止拨打 13 setResultData(null); 14 }else{ 15 num="12593"+num; //如果不是 在号码外加13593 16 setResultData(num);//重新设置结果数据,让广播将新号码继续传到拨号器那 17 } 18 } 19 20 }
posted on 2013-06-25 23:21 clarenceV1 阅读(1250) 评论(0) 编辑 收藏 举报