I am trying to answer calls programmatically. (I'm not even going to discuss the use of reflection, as this only works in froyo and earlier versions). My approach was to send a headset button event to answer a call. Unfortunately, this only works if a headset is connected to the phone, so I am sending a broadcast so that the phone thinks that the headset is connected as follows:
Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
headSetUnPluggedintent.putExtra("state", 1);
headSetUnPluggedintent.putExtra("name", "Headset");
sendOrderedBroadcast(headSetUnPluggedintent, null);
Call successfully received. BUT after that I have to "disconnect" the headset, otherwise there is no sound (since it is redirected to a fake headset). Therefore, I send another broadcast, like the previous one, setting the status key to 0. But this does not work. The virtual headset is still connected. Can anyone help with this?
This headache seems to be gone with the simple Clean project. It's just an Eclipse that makes fun of me AGAIN. Now the code is working fine.
source
share