Android 实现挂电话和接电话
Android 实现挂电话和接电话
在src文件夹下创建包com.Android.internal.telephony,在包下建一个文件ITelephony.aidl
文件内容如下:
- package com.android.internal.telephony;
- interface ITelephony{
- boolean endCall();
- void answerRingingCall();
- }
在你要调用的文件中:
- private static ITelephony getITelephony(Context context) {
- TelephonyManager mTelephonyManager = (TelephonyManager) context
- .getSystemService(TELEPHONY_SERVICE);
- Class<TelephonyManager> c = TelephonyManager.class;
- Method getITelephonyMethod = null;
- ITelephony iTelephony = null ;
- try {
- getITelephonyMethod = c.getDeclaredMethod("getITelephony",
- (Class[]) null); // 获取声明的方法
- getITelephonyMethod.setAccessible(true);
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
- try {
- iTelephony = (ITelephony) getITelephonyMethod.invoke(
- mTelephonyManager, (Object[]) null); // 获取实例
- return iTelephony;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return iTelephony;
- }
评论暂时关闭