Android--The implementation of self-active hanging up the phone

Source: Internet
Author: User
Tags dialpad

Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/47072451

Through "Android--aidl Summary" and "Android--aidl in depth" two blog posts. I believe you have a certain understanding of Android Aidl. Below, we use the aidl of Android to realize the function that we actively hang up the telephone, OK. Not much to say, we go directly to the subject.

1. Prepare Aidl File

The aidl files that hang up the phone are all files that come with Android, and we can find the two files from the Android source, each of which is neighboringcellinfo.aidl and itelephony.aidl

I put the neighboringcellinfo.aidl under the Android.telephony package of the project. Put the itelephony.aidl under the Com.android.internal.telephony bag.

Neighboringcellinfo.aid details such as the following:

/*//device/java/android/android/content/intent.aidl**** Copyright, the android Open Source project**** Licensed Under the Apache License, Version 2.0 (the "License"); * * Do not use this file except in compliance with the license.* * Obtain a copy of the License at****     http://www.apache.org/licenses/license-2.0**** unless required by applic Able law or agreed to in writing, software** distributed under the License are distributed on a "as is" basis,** without W Arranties or CONDITIONS of any KIND, either express OR implied.** see the License for the specific language governing perm Issions and** Limitations under the License.*/package android.telephony;parcelable neighboringcellinfo;
Itelephony.aidl details such as the following:

/* Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License") ; * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by appli Cable law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, * without Warranties or CONDITIONS of any KIND, either express OR implied. * See the License for the specific language governing permissions and * limitations under the License. */package Com.android.internal.telephony;import Android.os.bundle;import Java.util.list;import  android.telephony.neighboringcellinfo;/** * Interface used to interact with the phone.  Mostly this was used by the * Telephonymanager class. A few places is still using this directly. * Please clean them up if possible and use Telephonymanager Insteadl.   * * {@hide} */interface itelephony {/**  * Dial a number. This doesn ' t place the call.     IT Displays * the Dialer screen. * @param number The number to be dialed.     If NULL, this * would display of the Dialer screen with no number pre-filled.    */void Dial (String number);     /** * Place a call to the specified number.     * @param number The number to be called.    */void Call (String number);     /** * If There is currently a call in progress, show the call screen.  * The DTMF Dialpad may or May is visible initially, depending on * whether it is up and the user last exited the     Incallscreen.     * * @return True if the call is shown.    */Boolean Showcallscreen (); /** * Variation of Showcallscreen () that also specifies whether the * DTMF Dialpad should is initially visible whe     n the Incallscreen * comes up. * * @param showdialpad If True, make the dialpad visible initially, * otherwise hide the Dialpa     D initially. * @return TRue if the call is shown.    * * @see Showcallscreen */Boolean Showcallscreenwithdialpad (Boolean showdialpad);    /** * End call or go to the Home screens * * @return Whether it hung up */Boolean endcall ();     /** * Answer the currently-ringing call.  * If there ' s already a current active call, that's call would be * automatically put on hold.     If both lines is currently in use, the * current active call would be ended.  * * Todo:provide a flag to let the caller specify "what policy to use * if both lines is in use. (The current behavior are hardwired to * "answer incoming, end ongoing", which are how the call button * is specced     to behave.)     * * Todo:this should is a oneway call (especially since it's called * directly from the key queue thread).    */void Answerringingcall ();     /** * Silence the ringer if an incoming call is currently ringing. * (If vibrating, stop the vibrator Also.)  * * It's safe to call this if the ringer have already been silenced, or * even if there ' no incoming call.     (If So, the This method would do nothing.)     * * Todo:this should is a oneway call too (see above).     * (actually *all* the methods here, return void can * probably be oneway.)    */void Silenceringer ();     /** * Check If we are in either a active or holding call * @return True if the phone was offhook.    */Boolean Isoffhook ();     /** * Check If an incoming phone call are ringing or call waiting.     * @return True if the phone is ringing.    */Boolean isringing ();     /** * Check If the phone is idle.     * @return True if the phone is IDLE.    */Boolean isidle ();     /** * Check to see if the radio are on or not.     * @return Returns TRUE if the radio is on.    */Boolean Isradioon ();     /** * Check if the SIM pin lock is enabled. * @return True if the SIM pin lock is EnabLed.    */Boolean issimpinenabled ();     /** * Cancels the missed calls notification.    */void Cancelmissedcallsnotification ();  /** * supply a PIN to unlock the SIM.     Blocks until a result is determined.     * @param pin the pin to check.     * @return Whether the operation was a success.    */Boolean Supplypin (String pin); /** * Handles PIN MMI commands (PIN/PIN2/PUK/PUK2), which is initiated * without SEND (so <code>dial</co     De> is not appropriate).     * * @param dialstring the MMI command to be executed.     * @return True if MMI command is executed.    */Boolean Handlepinmmi (String dialstring);     /** * Toggles the radio on or off.    */void Toggleradioonoff ();    /** * Set the radio to ON or off */Boolean Setradio (Boolean turnOn);    /** * Request to update the location information on service state */void updateservicelocation ();     /** * Enable Location update notifications. */Void Enablelocationupdates ();     /** * Disable Location update notifications.    */void Disablelocationupdates ();     /** * Enable a specific APN type.    */int Enableapntype (String type);     /** * Disable a specific APN type.    */int Disableapntype (String type);     /** * Allow mobile data connections.    */Boolean enabledataconnectivity ();     /** * Disallow mobile data connections.    */Boolean disabledataconnectivity ();     /** * Whether data connectivity is possible.    */Boolean isdataconnectivitypossible ();    Bundle getcelllocation ();     /** * Returns The neighboring cell information of the device.     */list<neighboringcellinfo> Getneighboringcellinfo ();     int getcallstate ();     int getdataactivity ();    int getdatastate ();     /** * Returns The current active phone type as Integer. * Returns TELEPHONYMANAGER.PHONE_TYPE_CDMA if Rilconstants.cdma_phone * and telephonymanager.phone_type_gsm if RILConstants.gsm_phone */int getactivephonetype ();    /** * Returns the CDMA ERI icon Index to display */int getcdmaeriiconindex ();    /** * Returns the CDMA ERI icon mode, * 0-on * 1-flashing */int getcdmaeriiconmode ();    /** * Returns The CDMA ERI text, */String getcdmaeritext ();     /** * Returns True if CDMA provisioning needs to run.    */Boolean getcdmaneedsprovisioning ();    /** * Returns The unread count of voicemails */int getvoicemessagecount ();        /** * Returns the network type */int getnetworktype (); /** * Return True if an ICC card is present */Boolean Hasicccard ();}
After you have prepared the file, you will proactively generate the same package as the two files in the project's Gen folder, and you will generate the Itelephony.java file yourself at the same time.

For example, with:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

2, New Phoneutils class. and write a Method Endcall ()

This method is the way to hang up the phone. Detailed implementations such as the following

Hang up the phone public void Endcall (String incomingnumber) {try {class<?> clazz = Class.forName ("Android.os.ServiceManager "); method = Clazz.getmethod ("GetService", String.class), IBinder IBinder = (ibinder) method.invoke (NULL, Context.telephony_service); Itelephony itelephony = ITelephony.Stub.asInterface (IBinder); Itelephony.endcall ();} catch (Exception e) {e.printstracktrace ();}}
3. Permission to register

Finally, don't forget to register your permission in the Androidmanifest.xml file.

Detailed implementations such as the following:

<uses-permission android:name= "Android.permission.CALL_PHONE"/>

Android--The implementation of self-active hanging up the phone

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.