我能够阻止android中的来电,但是在断开时间之前它会响几秒钟。如何在不响铃的情况下直接断开电话?
我在Manifest
文件中添加了权限:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-feature android:name="android.hardware.telephony" />
然后创建 IDL
用于获取核心电话服务的接口。
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
然后为来电制作广播接收器。
public class PhonecallReceiver extends BroadcastReceiver {
Context context = null;
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Receving call...");
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService = (ITelephony) m.invoke(telephony);
Bundle b = intent.getExtras();
String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
telephonyService.endCall();
}catch (Exception e){ e.printStackTrace();
}}