我有以下BroadcastReceiver
课程来阻止来电。
public class CallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
telephonyService.endCall();
} catch (Exception e) {
System.out.println("error on end call : "+e.getMessage());
e.printStackTrace();
}
}
}
一切都按预期工作但我的问题是,telephonyService.endCall();
每次都有延迟。意思是,我可以在断开之前听到一小部分铃声。
另外,endCall()
断开的呼叫不计入未接来电,而是计入来电。这是默认行为吗?
感谢您的任何意见。