如何更换标准的Android拨号程序

时间:2012-06-25 08:14:46

标签: android

  

可能重复:
  How to intercept incoming calls android 2.3.x

我正在创建一个覆盖默认电话屏幕的应用程序,我需要与Android 2.3兼容。

目前我有这段代码:

private void answerCallAidl() throws RemoteException {
    // telephonyService.silenceRinger();       -------not work on 2.3
    // telephonyService.answerRingingCall();   -------not work on 2.3

    Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
    headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    headSetUnPluggedintent.putExtra("state", 1); // 0 = unplugged  1 = Headset with microphone 2 = Headset without microphone
    headSetUnPluggedintent.putExtra("name", "Headset");

    // TODO: Should we require a permission?
    sendOrderedBroadcast(headSetUnPluggedintent, null);

    Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);           
    buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
                          KeyEvent.KEYCODE_HEADSETHOOK));
    sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

    // froyo and beyond trigger on buttonUp instead of buttonDown
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);             
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
                           KeyEvent.KEYCODE_HEADSETHOOK));
    sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
} 


private void ignoreCallAidl() throws RemoteException {
    // telephonyService.silenceRinger();     -------not work on 2.3
    // telephonyService.endCall();           -------not work on 2.3
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);             
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_HEADSETHOOK));
    sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
}

我的问题是:

  1. 我无法拒绝来电。
  2. 它不适用于版本2.3.5。
  3. 我希望我的应用更换默认电话屏幕。
  4. 我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

简单来说 - 这是不可能的。

之前在JAVA中有一个作弊(使用反射),但现在它已不再可用了。请参考下面,

Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony)m.invoke(tm);

您应该参考this链接;这说明这是不可能的。我建议你在读完这篇文章后立即放弃这个想法。