Android directly rejects incoming calls

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.