android2.3 电话接听解决办法

android2.3 电话接听解决方法

  这段时间做个来电方面的应用,android2.2下面可以直接利用反射机制调获取ITelephony.answerRingingCall(),可以实现接听电话。但android2.3下面这个方法已经被禁用了。

  一下为android2.3接听电话解决方法

AudioManager localAudioManager = (AudioManager) paramContext
     .getSystemService("audio");
   int i2 = 1;
   int i1 = 79;

   boolean bool1 = localAudioManager.isWiredHeadsetOn();

   if (!bool1) {

    Intent localIntent3 = new Intent(
      "android.intent.action.HEADSET_PLUG");
    localIntent3.putExtra("state", 1);
    localIntent3.putExtra("microphone", 0);
    localIntent3.putExtra("name", "");
    paramContext.sendBroadcast(localIntent3);

    Intent meida_button = new Intent(
      "android.intent.action.MEDIA_BUTTON");
    KeyEvent localKeyEvent2 = new KeyEvent(i2, i1);
    meida_button.putExtra("android.intent.extra.KEY_EVENT",
      localKeyEvent2);

    paramContext.sendOrderedBroadcast(meida_button, null);
    Intent headset_plug = new Intent(
      "android.intent.action.HEADSET_PLUG");

    headset_plug.putExtra("state", 0);
    headset_plug.putExtra("microphone", 0);
    headset_plug.putExtra("name", "");
    paramContext.sendBroadcast(headset_plug);

   } else {

    Intent meida_button = new Intent(
      "android.intent.action.MEDIA_BUTTON");
    KeyEvent localKeyEvent1 = new KeyEvent(i2, i1);
    meida_button.putExtra("android.intent.extra.KEY_EVENT",
      localKeyEvent1);
    paramContext.sendOrderedBroadcast(meida_button, null);

   } 

1 楼 蜗牛/ 2011-12-30  
很感谢你的代码,不过还可以去优化一下android2.3 电话接听解决办法
2 楼 hustpeng 2012-02-24  
太感谢了,很强大的实现
3 楼 hustpeng 2012-02-24  
伪造一个插入有线耳机,并按下接听键的广播,楼主太聪明了
4 楼 717693247 2012-03-07  
不错,后面我们也是发了一个接入耳机的广播来实现接听的,不过这种方式并不是所有的手机都有用的,楼主你确定很聪明
5 楼 silence3613 2012-05-10  
android2.3 电话接听解决办法 楼主的方式真是非常的好啊 。谢谢资源共享。