转载请注明出处: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. PCB SQL MS 将多行有序数据转为一行数据(一列转一行)

    一.原数据:多行有序 SELECT CC.techname FROM PPEflow BB LEFT JOIN pubgyxxb CC ON BB.techno = CC.techno ORDER B ...

  2. thinkphp data方法

    data方法也是模型类的连贯操作方法之一,用于设置当前要操作的数据对象的值,可能大家不太习惯用这个方法,今天来讲解下如何用好data方法. 用法 写操作 通常情况下我们都是通过create方法或者赋值 ...

  3. .NET Core Run On Docker By Kubernetes 系列文章汇总

    前言介绍 .NET Core是微软新一代主力编程平台,开源.免费.跨平台.轻量级.高性能,支持Linux.Docker.k8s等环境,适合开发微服务.云原生.大型互联网应用.全开源解决方案. Dock ...

  4. MarkDown流程图概要

    要素 流程元素定义: 名称=>类型: 显示名称 控制流程定义: 名称1([yes,no],right)->名称2 注意事项 流程元素定义在代码上部, 流程走向定义在代码下部 名称可以取中文 ...

  5. 4.Flask-alembic数据迁移工具

    alembic是用来做ORM模型与数据库的迁移与映射.alembic使用方式跟git有点类似,表现在两个方面,第一个,alemibi的所有命令都是以alembic开头: 第二,alembic的迁移文件 ...

  6. MySQL安装for windows

    ======MySQL安装 for windows====== 版本5.7.X MySQL服务器帮助我们来管理文件的操作 MySQL软件 - 服务器端软件 - 服务端程序 - 解析指令 - 对文件的操 ...

  7. Spring Boot (21) 使用Swagger2构建restful API

    使用swagger可以与spring mvc程序配合组织出强大的restful api文档.它既可以减少我们创建文档的工作量,同时说明内容又整合入现实代码中,让维护文档和修改代码整合为一体,可以让我们 ...

  8. SQL Server中,with as使用介绍

    一.WITH AS的含义      WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候 ...

  9. css3基础篇三

    CSS3 文本阴影 在 CSS3 中,text-shadow 可向文本应用阴影. 您能够规定水平阴影.垂直阴影.模糊距离,以及阴影的颜色: 实例 向标题添加阴影: h1 { text-shadow: ...

  10. C# MVC 延时

    [System.Runtime.InteropServices.DllImport("kernel32.dll")] static extern uint GetTickCount ...