我要断开的ICS呼出。
我的问题是,首先我没有收到广播的IC`姜饼它工作正常,并阻止了电话,但在ICS它不是广播。
有关广播我创建了一个服务,在我收到广播 PHONE_STATE
的ICS还但是当我尝试断开呼叫我得到的错误
没有这样的方法名getITelephony
在ICS呼叫未断开连接。
我使用下面的code断开通话使用广播...
尝试{
TelephonyManager经理=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
C类=的Class.forName(manager.getClass()的getName());
方法米= c.getDeclaredMethod(getITelephony);
m.setAccessible(真正的);
ITelephony电话=(ITelephony)m.invoke(经理);
telephony.endCall();
}赶上(例外五){
Log.d(,e.getMessage());
}
AndroidMaifest.xml
PhonecallStateBroadcastReceiver.java
与packgename 包com.android.internal.telephony;
ITelephony.aidl
接口ITelephony
{
布尔结束呼叫();
无效answerRingingCall();
无效silenceRinger();
}
解决方案
1)下载这个类: ITelephony
2)添加这class.java在您的项目在包:com.android.internal.telephony
3)加入这个权限在你的清单:
<使用-权限的Android:名称=android.permission.READ_PHONE_STATE/>
<使用-权限的Android:名称=android.permission.MODIFY_PHONE_STATE/>
<使用-权限的Android:名称=android.permission.CALL_PHONE/>
和该接收器应用应答器:
<接收机器人:名称=。CallReceiver>
<意向滤光器>
<作用机器人:名称=android.intent.action.PHONE_STATE/>
&所述; /意图滤光器>
< /接收器>
4)创建CallReceiver类:
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
ITelephony telephonyService = getTeleService(上下文);
如果(telephonyService!= NULL){
尝试 {
字符串numberCall = intent.getExtras()的getString(TelephonyManager.EXTRA_INCOMING_NUMBER)。
Log.i(TAG,CALL民:+ numberCall);
如果(numberCall.equals(TEST_NUMBER)){
telephonyService.endCall();
Toast.makeText(背景下,结束通话:+ numberCall,Toast.LENGTH_LONG).show();
Log.i(TAG,挂断);
} 其他 {
Log.i(TAG,接受CALL);
}
}赶上(例外五){
e.printStackTrace();
Log.i(TAG,CATCH CALL);
}
}
}
私人ITelephony getTeleService(上下文的背景下){
TelephonyManager TM =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
尝试 {
方法米=的Class.forName(tm.getClass()的getName()。)getDeclaredMethod(getITelephony);
m.setAccessible(真正的);
返程(ITelephony)m.invoke(TM);
}赶上(例外五){
e.printStackTrace();
}
返回null;
}
i want to disconnect outgoing call in ICS.
My issue is first of all I am not getting the broadcast in IC` in Gingerbread it is working fine and blocking the calls but in ICS its not Broadcasting.
for BroadCast I created a service and in that I am getting BroadCast of PHONE_STATE
in ICS also but when i try to disconnect call I am getting error of
NO such method name 'getITelephony'
in ICS call is not disconnecting.
I am using following code to disconnect call using the BroadCast...
try{
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class c = Class.forName(manager.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephony = (ITelephony)m.invoke(manager);
telephony.endCall();
} catch(Exception e){
Log.d("",e.getMessage());
}
AndroidMaifest.xml
PhonecallStateBroadcastReceiver.java
with packgename of package com.android.internal.telephony;
ITelephony.aidl
interface ITelephony
{
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
解决方案
1) Download this class : ITelephony
2) Add this class.java in your project in package: com.android.internal.telephony
3) Add this permission in your manifest :
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
And this receiver in application balise :
<receiver android:name=".CallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
4) Create CallReceiver class :
@Override
public void onReceive(Context context, Intent intent) {
ITelephony telephonyService = getTeleService(context);
if(telephonyService!=null) {
try {
String numberCall = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.i("TAG", "CALL NUM: " + numberCall);
if(numberCall.equals(TEST_NUMBER)) {
telephonyService.endCall();
Toast.makeText(context, "END CALL: " + numberCall, Toast.LENGTH_LONG).show();
Log.i("TAG", "END CALL");
} else {
Log.i("TAG", "ACCEPT CALL");
}
} catch (Exception e) {
e.printStackTrace();
Log.i("TAG", "CATCH CALL");
}
}
}
private ITelephony getTeleService(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Method m = Class.forName(tm.getClass().getName()).getDeclaredMethod("getITelephony");
m.setAccessible(true);
return (ITelephony) m.invoke(tm);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
相关推荐
最新文章