Android 拦截去电

android 拦截去电

在manifest.xml文件中添加拦截去电的权限

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

编写去电监听广播接收者

package com.xx.secret;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import android.os.Build;
/**
 * Created on 2016/7/7 0007.
 *
 */
public class MediaReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getAction()) {
            case Intent.ACTION_NEW_OUTGOING_CALL:
                String phone = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
                endCall(context);
                break;                   
        }
    }

    private void endCall(Context context) {
        String number = null;
        //正常的系统要挂断电话直接返回null就可以,但是海信的要返回空字符串才行
        if (Build.MANUFACTURER.toLowerCase().contains("hisense"))
            number = "";
        setResultData(number);//拦截外拨电话
    }
}

在manifest.xml文件中注册去电监听广播

  <receiver android:name="com.xx.secret.MediaReceiver"
             >
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
 </receiver>

猜你喜欢

转载自blog.csdn.net/loveliwenyan2012/article/details/79636430