Android 拦截去电

2019-04-13 13:01发布

android 拦截去电

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

"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文件中注册去电监听广播

"com.xx.secret.MediaReceiver" > "1000"> "android.intent.action.NEW_OUTGOING_CALL" />