简体   繁体   中英

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

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. this file ( ITelephony.java ) has a function called endcall() which uses permissions. this is not advised by google team as recieving and ending calls in a programmatic way is invasion of user privacy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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