转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47072451

通过《Android之——AIDL小结》与《Android之——AIDL深入》两篇博文。相信大家已经对Android
AIDL有了一定的了解。以下,我们就利用Android的AIDL实现自己主动挂断电话的功能,好了。不多说了,我们直接进入主题。

1、准备AIDL文件

挂断电话的AIDL文件都是Android自带的文件,我们能够从Android的源码中找到这两个文件,它们各自是NeighboringCellInfo.aidl和ITelephony.aidl

我把NeighboringCellInfo.aidl放在项目的android.telephony包下。将ITelephony.aidl放在com.android.internal.telephony包下

NeighboringCellInfo.aid详细内容例如以下:

/* //device/java/android/android/content/Intent.aidl
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "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 android.telephony; parcelable NeighboringCellInfo;

ITelephony.aidl详细内容例如以下:

/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "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 is used by the
* TelephonyManager class. A few places are 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 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 not be visible initially, depending on
* whether it was up when the user last exited the InCallScreen.
*
* @return true if the call screen was shown.
*/
boolean showCallScreen(); /**
* Variation of showCallScreen() that also specifies whether the
* DTMF dialpad should be initially visible when the InCallScreen
* comes up.
*
* @param showDialpad if true, make the dialpad visible initially,
* otherwise hide the dialpad initially.
* @return true if the call screen was shown.
*
* @see showCallScreen
*/
boolean showCallScreenWithDialpad(boolean showDialpad); /**
* End call or go to the Home screen
*
* @return whether it hung up
*/
boolean endCall(); /**
* Answer the currently-ringing call.
*
* If there's already a current active call, that call will be
* automatically put on hold. If both lines are currently in use, the
* current active call will be ended.
*
* TODO: provide a flag to let the caller specify what policy to use
* if both lines are in use. (The current behavior is hardwired to
* "answer incoming, end ongoing", which is how the CALL button
* is specced to behave.)
*
* TODO: this should be 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 has already been silenced, or
* even if there's no incoming call. (If so, this method will do nothing.)
*
* TODO: this should be a oneway call too (see above).
* (Actually *all* the methods here that return void can
* probably be oneway.)
*/
void silenceRinger(); /**
* Check if we are in either an active or holding call
* @return true if the phone state is OFFHOOK.
*/
boolean isOffhook(); /**
* Check if an incoming phone call is ringing or call waiting.
* @return true if the phone state is RINGING.
*/
boolean isRinging(); /**
* Check if the phone is idle.
* @return true if the phone state is IDLE.
*/
boolean isIdle(); /**
* Check to see if the radio is 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 are initiated
* without SEND (so <code>dial</code> 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 location information in 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(); /**
* Report 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();
}

准备好文件后,会在项目的gen文件夹下自己主动生成与两个文件所在包一样的包,同一时候会自己主动生成ITelephony.java文件

例如以下图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

2、新建PhoneUtils类。并写一个方法endCall()

这种方法就是挂断电话的方法。详细实现例如以下

//挂断电话
public void endCall(String incomingNumber){
try {
Class<?> clazz = Class.forName("android.os.ServiceManager");
Method 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、注冊权限

最后别忘了在AndroidManifest.xml文件里注冊权限

详细实现例如以下:

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

Android之——自己主动挂断电话的实现的更多相关文章

  1. android 自动拨打电话 挂断电话代码

    页面布局文件代码  (  res下面的layout下面的activity_main.xml代码 ) <RelativeLayout xmlns:android="http://sche ...

  2. Android自动接听&挂断电话(包含怎么应对4.1以上版本的权限检

    一  前言 这两天要研究类似白名单黑名单以及手势自动接听的一些功能,所以呢,自然而然的涉及到怎么自动接听/挂断电话的功能了.对于自动接听这一块,android4.1版本及其以上的版本和之前的版本处理逻 ...

  3. Android 实现自动接听和挂断电话功能

    添加权限 <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permis ...

  4. Android 电话自己主动接听和挂断具体解释

    1.通过aidl及反射实现挂断电话 详细分三步: (1)ITelephony.aidl ,必须新建com.android.internal.telephony包并放入ITelephony.aidl文件 ...

  5. Eclipse Android 代码自己主动提示功能

    Eclipse Android 代码自己主动提示功能 Eclipse for android 实现代码自己主动提示智能提示功能.介绍 Eclipse for android 编辑器中实现两种主要文件 ...

  6. android 视频通话开启呼叫等待后,来第三方的视频通话,接通后通话时间一直显示为0,过几秒之后视频通话自己主动挂断

    开启通话设置视频通话的"来电等待"; 步骤1:測试机和配合机A处于视频通话过程中; 步骤2:配合机B向測试机呼出视频电话; 步骤3:測试机接听配合机B的视频来电; 现象:视频通话过 ...

  7. Android TextView自己主动换行文字排版參差不齐的原因

    今天项目没什么进展,公司后台出问题了.看了下刚刚学习Android时的笔记,发现TextView会自己主动换行,并且排版文字參差不齐.查了下资料,总结原因例如以下: 1.半角字符与全角字符混乱所致:这 ...

  8. Android Monkey自己主动化測试

    前言 假设你做Android开发,还没有使用过Monkey进行測试,那么今天看到这篇文章,希望能解决你Android測试中的一些问题.起码能帮你省点測试的时间而且发现很多其它的问题. Monkey简单 ...

  9. Android简易实战教程--第十话《模仿腾讯手机助手小火箭发射详解》

    之前对系统自带的土司的源码做了简要分析,见博客:点击打开链接 这一篇给一个小案例,自定义土司,模拟腾讯卫士的小火箭发射.如果想要迅速看懂代码,建议先去看一下上篇介绍点击打开链接 首先,定义一个服务,在 ...

随机推荐

  1. Django day01 web应用程序 , http协议

    一:web应用程序1.什么是web应用程序 是一种可以通过web访问的应用程序,最大的好处就是, 只要有浏览器,用户就能很容易访问到应用程序 2. web应用程序的优缺点 缺点: 应用程序强调了浏览器 ...

  2. wps 2016 个人版 重新开始编号

    wps文档重新开始编号,继续编号,自定义编号 首先选中这一行 鼠标右键选中项目符号和编号 单击项目符号和编号,你可以重新开始编号为1,继续前一列表,还可自定义,单击确定按钮就可以实现你想要的结果 效果 ...

  3. Get 和 Post

    理论: Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而 ...

  4. Android 权限管理(持续整理)

    1. Android 6.0之后,APP可以直接安装,运行时再询问用户授予相关权限,此时系统弹出一个对话框,(这个对话框不能由开发者定制) 同时用户也可以在手机的“设置”中对于某个App进行权限管理 ...

  5. [原创]Linux(CentOS)下安装mongodb

    和上一篇一样,装个这个踩了无数个坑…… 1.下载 wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel55-3.2.12.tgz ...

  6. 设置浏览器让js报错

    ie-工具---internet选项--高级--“禁用脚本提示”前面那个框的勾去掉---“显示每个脚本错误的通知”给该项打勾 注意:此时是静态页面很容易提示出错误的行号,但是当js是动态页面的时候,浏 ...

  7. 使用CMD建立指定格式的文件

    一.建立空文件的几种方法1.cd.>a.txtcd.表示改变当前目录为当前目录,即等于没改变:而且此命令不会有输出.>表示把命令输出写入到文件.后面跟着a.txt,就表示写入到a.txt. ...

  8. iOS 加密算法汇总

    CCCryptorStatus CCCryptorCreate( CCOperation op,             /* kCCEncrypt, etc. */ CCAlgorithm alg, ...

  9. javascript 数组 常用方法

    前言  学学忘忘  闲来做个笔记 整理下数组常用方法. Array 数组常用方法  创建数组的基本方式有两种    1.第一种是使用Array构造函数,  var arr = new Array(); ...

  10. 洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk【贪心+背包】

    由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此 ...