How to programmatically answer a call in Android 4.0.3?

后端 未结 3 1282
囚心锁ツ
囚心锁ツ 2021-01-16 16:50

So as the subject states I need to be able to answer a phone call programmatically in Android 4.0.3 on an HTC OneX. I have read several places that the MODIFY_PHONE_ST

相关标签:
3条回答
  • 2021-01-16 17:22

    After days of research, I found that using both a broadcast receiver route and a runtime.exec() route it is simply not possible to answer a phone call in Android 4.0.3 using the Android API.

    For those of you still wondering, I did find some useful information...You CAN answer a call through adb using the command adb shell input keyevent 5 5 is the key code for the call button and in Android it is the KEYEVENT_CALL

    0 讨论(0)
  • 2021-01-16 17:34

    Here are several useful links, check them:

    1. Answer automatically to Incoming Call
    2. How to auto answer call programmatically
    3. Auto answer
    0 讨论(0)
  • 2021-01-16 17:44

    This works from Android 2.2 to 4.0 and now after adding the try catch to the last line it works for 4.1.2 and 4.2 Frankly speaking dont know how it works but it works for me.

              Log.d(tag, "InSecond Method Ans Call");
        // 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");
    
        Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
        headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
        headSetUnPluggedintent.putExtra("state", 0);
        headSetUnPluggedintent.putExtra("name", "Headset");
        try {
            sendOrderedBroadcast(headSetUnPluggedintent, null);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    This is working for me in Android 4.1.2 as well as i have tested on 4.2 This still gives an exception which is handled.

    0 讨论(0)
提交回复
热议问题