Hi
I'm writing an Android app to auto-answer incoming calls. I am using a receiver, and trying to send ACTION_MEDIA_BUTTON event when the phone rings.
It all works great on the emulator - When the phone rings it actually answers the call automatically.
But when I'm trying it on the device it-self it just does not work (HTC Legend).
This is the code:
// trigger on buttonUp instead of buttonDown
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown .putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonDown , "android.permission.CALL_PRIVILEGED");
// 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));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
And this is the receiver code in the XML file:
<receiver android:name=".PhoneOutgoingCallReceiver" android:enabled="true">
<intent-filter android:priority="0">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<receiver android:name=".PhoneIncomingCallReceiver" android:enabled="true">
<intent-filter android:priority="0">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
Anyone knows why it does not work on the real device? what are the different?
Thanks!