Android之——自己主动挂断电话的实现
转载请注明出处: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之——自己主动挂断电话的实现的更多相关文章
- android 自动拨打电话 挂断电话代码
页面布局文件代码 ( res下面的layout下面的activity_main.xml代码 ) <RelativeLayout xmlns:android="http://sche ...
- Android自动接听&挂断电话(包含怎么应对4.1以上版本的权限检
一 前言 这两天要研究类似白名单黑名单以及手势自动接听的一些功能,所以呢,自然而然的涉及到怎么自动接听/挂断电话的功能了.对于自动接听这一块,android4.1版本及其以上的版本和之前的版本处理逻 ...
- Android 实现自动接听和挂断电话功能
添加权限 <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permis ...
- Android 电话自己主动接听和挂断具体解释
1.通过aidl及反射实现挂断电话 详细分三步: (1)ITelephony.aidl ,必须新建com.android.internal.telephony包并放入ITelephony.aidl文件 ...
- Eclipse Android 代码自己主动提示功能
Eclipse Android 代码自己主动提示功能 Eclipse for android 实现代码自己主动提示智能提示功能.介绍 Eclipse for android 编辑器中实现两种主要文件 ...
- android 视频通话开启呼叫等待后,来第三方的视频通话,接通后通话时间一直显示为0,过几秒之后视频通话自己主动挂断
开启通话设置视频通话的"来电等待"; 步骤1:測试机和配合机A处于视频通话过程中; 步骤2:配合机B向測试机呼出视频电话; 步骤3:測试机接听配合机B的视频来电; 现象:视频通话过 ...
- Android TextView自己主动换行文字排版參差不齐的原因
今天项目没什么进展,公司后台出问题了.看了下刚刚学习Android时的笔记,发现TextView会自己主动换行,并且排版文字參差不齐.查了下资料,总结原因例如以下: 1.半角字符与全角字符混乱所致:这 ...
- Android Monkey自己主动化測试
前言 假设你做Android开发,还没有使用过Monkey进行測试,那么今天看到这篇文章,希望能解决你Android測试中的一些问题.起码能帮你省点測试的时间而且发现很多其它的问题. Monkey简单 ...
- Android简易实战教程--第十话《模仿腾讯手机助手小火箭发射详解》
之前对系统自带的土司的源码做了简要分析,见博客:点击打开链接 这一篇给一个小案例,自定义土司,模拟腾讯卫士的小火箭发射.如果想要迅速看懂代码,建议先去看一下上篇介绍点击打开链接 首先,定义一个服务,在 ...
随机推荐
- Java插入中文到数据库中文变成问号解决
转自:https://blog.csdn.net/hellosweet1/article/details/81673152 之所以会出现乱码,就是编码方式不一致导致的 我们应该首先确定 ...
- aspectc中this可以获取的东西
this->kind 操作类型 this->targetName 被调用函数名称 this->funcName 调用函数名称 this->argsCount 参数个数 thi ...
- 最短路径问题(floyd)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1867 #include<stdio.h& ...
- [Apple开发者帐户帮助]三、创建证书(7)创建证书签名请求
Mac上的Keychain Access允许您创建证书签名请求(CSR). 启动位于的Keychain Access /Applications/Utilities. 选择Keychain Acces ...
- Python27天 反射 ,isinstance与ssubclass 内置方法
所学内容 反射 1.hasattr ( 判断一个属性在对象里有没有 ) -------------------- [对象,字符串属性]本质是:# 判断 ' name ' in obj.__dict__ ...
- ZOJ2477 Magic Cube
题目: This is a very popular game for children. In this game, there's a cube, which consists of 3 * 3 ...
- 5.20rieds切换数据库
- sql学习--insert
insert的四种插入方式 第一种最简单的 into 和目标列的列表是可选的 intsert [into] tableA [(col1,col2)] values(val1,val2) 第二种 ins ...
- mongodb 下载与安装文档
MongoDB数据库安装及配置环境(windows10系统) windows10系统下MongoDB的安装及环境配置: MongoDB的安装 下载地址: https://www.mongodb.c ...
- 微信小程序swiper bindChange重复执行
swiper是微信小程序的一个滑动组件,非常重要.如果只是做简单的轮播图而不进行复杂的逻辑,直接可以使用,甚至不需要知道组件的方法.今天在做一个如下的页面时,快速滑动swiper出现了问题: 控制台打 ...