简体   繁体   English

阻止来电-Android

[英]blocking Incoming call - Android

i have incoming call broadcast receiver and phone state listener class , how to block or reject incoming call and the ringing notification 我有来电广播接收器和电话状态侦听器类,如何阻止或拒绝来电以及响铃通知

BroadCastReceiver BroadCast接收器

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);            

    }
}

Phone Listener 电话听众

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);
}


}

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

To block a call u have to use java reflections and access hidden file of android.telephony package. 要阻止通话,您必须使用Java反射并访问android.telephony包的隐藏文件。 this file ( ITelephony.java ) has a function called endcall() which uses permissions. 该文件( ITelephony.java )具有一个名为endcall()的函数,该函数使用权限。 this is not advised by google team as recieving and ending calls in a programmatic way is invasion of user privacy. Google团队不建议您这样做,因为以编程方式接收和结束呼叫是对用户隐私的侵犯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM