From: http://www.hzhike.com/School/2011/201106/20110609222132.html
After a simple Google/Baidu, I found that android has no ready-made API to reject calls. Android can intercept text messages by registering broadcastreceiver. Because this broadcast is an ordered broadcast, the broadcast receiver can be terminated in advance as long as the priority is higher than that of the SMS receiver.
However, there is no similar mechanism for incoming calls. However, based on some information on the Internet, you can reject calls by taking the following steps:
1. register the broadcast receiver to monitor the mobile phone status:
Java code
<Cycler Android: Name = ". phonebroadcastreceiver">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. phone_state"/>
</Intent-filter>
</Cycler>
<Cycler Android: Name = ". phonebroadcastreceiver">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. phone_state"/>
</Intent-filter>
</Cycler>
When the phone receives a call, the broadcast receiver is triggered.
2. The most important thing is to obtain an API that can control the phone number.These APIs seem to be internal Android interfaces and are not exposed. For more information, see this post: http://topic.csdn.net/u/20091226/00/09e2979b-7c8c-4991-856d-586a278875c0.html
You need to manually add import when using it:
Java code
Import com. Android. Internal. telephony. itelephony;
Import com. Android. Internal. telephony. itelephony;
In the same way, stackoverflow has also been roughly mentioned below: http://stackoverflow.com/questions/1083527/how-to-block-calls-in-android
It is worth noting that, in this way, the broadcast receiver will be triggered twice. The first call is received, and the second call is triggered after the call endcall is rejected. When processing our own program logic, we can distinguish it by itelephony. getcallstate. This function returns 1 to indicate the incoming call, and 0 to indicate that the incoming call is rejected.
Finally, this method may still display the system's phone answering interface, and there will also be a call rejection record in the call records. This is probably because the order in which the system logic and broadcast receiver exist are processed by the system underlying layer. This article analyzes some of the source code.