Call Management in Android (2)-call hidden APIs

Source: Internet
Author: User


Android APIs do not provide a direct way to answer calls. In fact, the communication functions of answering calls and making calls are implemented by sending AT commands at the lowest level, when sending the AT command, you need to open an at port device file in the/dev/directory of the Linux system. Different mobile phones and firmware have different file names, therefore, using this underlying method is troublesome (involving knowledge about programming and communication in Linux ). Since the application layer of the Android system can call and answer calls through the interface, the source code of the android framework is public and starts from the source code.


Key Files
: Frameworks/base/telephony/Java/COM/Android/Internal/telephony/phone. Java

Phone. Java
It is an interface that provides many mobile phone-related methods, including rejecting incoming call rejectcall () and receiving incoming call acceptcall (), and other methods such as locking a mobile phone network (GSM, WCDMA, etc.
)... Phone is just an interface. How should I instantiate it? You can findPhonefactory
In this class, the static method getdefaultphone () can instantiate a phone object (It will be converted to GSM phone or cdmaphone based on the current mobile phone type instance. Of course, WCDMA instances will also be converted to GSM phone. This is not to mention. As for the TD mobile phone, ask China Mobile to ask for code.
).

Using the static method of phonefactory to directly instantiate the phone object, the phone function can be called at will. Now we only care about the rejectcall () and accptcall () functions.

The Code is as follows:

// Reference undisclosed APIs <br/> Import COM. android. internal. telephony. phone; <br/> Import COM. android. internal. telephony. phonefactory; <br/> Import COM. android. internal. telephone. callstateexception; <br/> public class Myphone () {<br/> private phone mphone = NULL; </P> <p> Public Myphone () {<br/> mphone = phonefactory. getdefaphone phone (); <br/>}< br/>/** call */<br/> Public void call (string number) {<br/> try <br/> {<br/> connection = phone. dial (number); </P> <p >}< br/> catch (callstateexception e) {<br/> // log. E (TAG, E. tostring (); <br/>}</P> <p>/** Answer call */<br/> Public void acceptcall () {<br/> try <br/> {<br/> phone. acceptcall (); <br/>}< br/> catch (callstateexception e) {<br/> // log. E (TAG, E. tostring ()); <br/>}</P> <p>/** reject call */<br/> Public void rejectcall () {<br/> try {<br/> phone. rejectcall (); <br/>} catch (callstateexception e) {<br/> // log. E (TAG, E. tostring (); <br/>}</P> <p>}

 

Put the code in eclipse, and you will find that you cannot import two key class names, phone and phonefactory, because androd. jar package does not contain these two classes, Google did not put them in the SDK, at least the current SDK1.5-2.2 is not, may be involved in legal issues.

To reference the API that is not disclosed to the SDK, you can directly compile the application into an APK file in the source code environment. Next section: Build the android source code environment under Ubuntu

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.