gpt4 book ai didi

java - 挂断来电

转载 作者:行者123 更新时间:2023-11-30 11:35:44 25 4
gpt4 key购买 nike

我正在尝试阻止 android 中的来电。我有这个 BroadcastReceiver 但它处理来电但不会阻止我的 android 2.3.6 手机上的来电(没有尝试其他版本)。这是我的接收器:

public class PhoneCallReceiver extends BroadcastReceiver {
Context context = null;
private static final String TAG = "Phone call";
private ITelephony telephonyService;

@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");

TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
// telephonyService.silenceRinger();

telephonyService.endCall();
} catch (Exception e) {
Log.v(TAG, "failed....");
e.printStackTrace();
}
}
}

和 ITelephony

package com.callblocker.mk;

interface ITelephony {

boolean endCall();

void answerRingingCall();

void silenceRinger();

}

最佳答案

在广播接收器中调用此方法

 public static void disconnectPhoneItelephony(Context context) {
ITelephony telephonyService;
Log.v(TAG, "Now disconnecting using ITelephony....");
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Log.v(TAG, "Get getTeleService...");
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: could not connect to telephony subsystem");
Log.e(TAG, "Exception object: " + e);
}
}

//广播接收者

 @Override
public void onReceive(Context context, Intent intent) {


if (!intent.getAction().equals("android.intent.action.PHONE_STATE"))
return;
else {

disconnectPhoneItelephony(context);
}}

// list

 <!-- BLOCK CALL -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />

<receiver android:name="receiver.CallReceiver" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>

关于java - 挂断来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com