设为首页 加入收藏

TOP

Android 结束通话--实现黑名单拦截(一)
2014-11-24 00:08:15 来源: 作者: 【 】 浏览:23
Tags:Android 结束 通话 实现 黑名单 拦截

1> 从Android的源代码中拷贝以下文件到项目中:
com.android.internal.telephony包下的ITelephony.aidl
android.telephony包下的NeighboringCellInfo.aidl
注意:需要在项目中建立对应的包名存放上述两个aidl文件,
如下图所示。开发工具会在gen目录下自动生成ITelephony.java




2> 调用ITelephony.endCall()结束通话:
Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
IBinder binder = (IBinder)method.invoke(null, new Object[]{TELEPHONY_SERVICE});
ITelephony telephony = ITelephony.Stub.asInterface(binder);
telephony.endCall();

在清单文件AndroidManifest.xml中添加权限:



代码示例:

DemoActivity.java:

package cn.itcast.endcall;


import java.lang.reflect.Method;


import com.android.internal.telephony.ITelephony;


import android.app.Activity;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;


public class DemoActivity extends Activity {
ITelephony iTelephony;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


try {
// 获取系统电话管理的服务
Method method = Class.forName("android.os.ServiceManager")
.getMethod("getService", String.class);
// 通过反射技术获得binder对象
IBinder binder = (IBinder) method.invoke(null,
new Object[] { TELEPHONY_SERVICE });
iTelephony = ITelephony.Stub.asInterface(binder);
} catch (Exception e) {
e.printStackTrace();
}
}


public void endcall(View view) {
try {
// iTelephony.endCall();
iTelephony.call("15139394270");
} catch (RemoteException e) {
e.printStackTrace();
}
}
}


另附NeighboringCellInfo.aidl:


/* //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 p

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android 欢迎界面设置 下一篇Python 之 paramiko 模块

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: