我试图拒绝拨打电话,甚至没有给主叫方拨打一个电话。 我试图拒绝这个代码的调用,但它拒绝一个环。
public boolean killCall(Context context) {
try {
// Get the boring old TelephonyManager
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Get the getITelephony() method
Class classTelephony = Class.forName(telephonyManager.getClass().getName());
Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");
// Ignore that the method is supposed to be private
methodGetITelephony.setAccessible(true);
// Invoke getITelephony() to get the ITelephony interface
Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);
// Get the endCall method from ITelephony
Class telephonyInterfaceClass =
Class.forName(telephonyInterface.getClass().getName());
Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");
methodEndCall.setAccessible(true);
// Invoke endCall()
methodEndCall.invoke(telephonyInterface);
} catch (Exception ex) { // Many things can go wrong with reflection calls
return false;
}
return true;
}
我在BroadcastReceiver的killCall(Context context)
中呼叫public void onReceive(Context context, Intent intent)
。我为我的应用设置了CALL_PHONE
和READ_PHONE_STATE
权限,以下是Manifest.xml中<receiver/>
的代码
<receiver
android:name=".PhoneCallReciever"
android:enabled="true"
android:exported="true"
>
<intent-filter android:priority="999">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
请帮帮我。