阻止来电 - Android

时间:2010-10-07 12:57:55

标签: android

我有来电广播接收器和电话状态监听器类,如何阻止或拒绝来电和响铃通知

BroadCastReceiver

public class PhoneCallReceiver extends BroadcastReceiver{

    private static final String TAG = "Phone call";

    @Override
    public void onReceive(Context context, Intent intent) {
            Log.v(TAG, "Receving....");
            TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            SamplePhoneStateListener customPhoneListener = new SamplePhoneStateListener();
            telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);            

    }
}

电话听众

public class SamplePhoneStateListener extends PhoneStateListener {

    private static final String TAG = "Phone Listner";

@Override
public void onCallStateChanged(int state, String incomingNumber) {
      Log.v(TAG, "Current State is - "+state);
      Log.v(TAG, incomingNumber);
      switch(state){
              case TelephonyManager.CALL_STATE_RINGING:
                      Log.d(TAG, "Phone Ringigg");
                      break;
      }    
     super.onCallStateChanged(state, incomingNumber);
}


}

2 个答案:

答案 0 :(得分:1)

确保您拥有android.permission.READ_PHONE_STATE权限设置。

答案 1 :(得分:0)

要阻止呼叫,您必须使用java反射并访问android.telephony包的隐藏文件。此文件(ITelephony.java)有一个名为endcall()的函数,它使用权限。谷歌团队不建议这样做,因为接收和以程序化方式结束通话是侵犯用户隐私。