Android 电话拦截

rivate String strAction="android.intent.action.NEW_OUTGOING_CALL";
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("===PhoneInterceptorReceiver.onReceive(Context context, Intent intent)=====");
        String action=intent.getAction();
        //系统发送的是外拨电话的信号
        if(strAction.equals(action)){
            //得到用户拨打的电话号码
           String number= getResultData();
            //由于接收用户外拨电话的广播接收者是最终广播,无法被终止,但可以通过将电话号码置空来阻止电话的拨打
            if(number.contains("5554")){
                //将电话号码置空,之后就算系统自动的广播接收者收到了信号,但由于没有电话号码而不知道给谁拨打
                this.setResultData(null);
            }
        }
    }
}

hsjwcfdeMacBook-Pro.local 16:36:03
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hsj.example.phoneinterceptordemo06" >

    <!--注册处理外拨电话的权限-->
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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=".receiver.PhoneInterceptorReceiver">
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>

  

posted @ 2016-01-14 16:39  呼啦啦,,啦啦呼呼  阅读(234)  评论(0编辑  收藏  举报