Some time ago I made a PSTN call application, and the pad was connected to the landline to implement the call function. The functions of turning the address book up and down are available on the landline. The address book uses Google's default address book. When the address book is not changed, only the analog button is used to send messages. The code is simple and shared !!
Public class menudemoactivity extends activity {protected static final string tag = "menudemoactivity"; @ override public void oncreate (bundle savedinstancestate) {requestwindowfeature (window. feature_no_title); super. oncreate (savedinstancestate); setcontentview (R. layout. main); Final button = (button) findviewbyid (R. id. button1); button. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {sendkeycode (keyevent. keycode_dpad_down) ;}}); Final button button2 = (button) findviewbyid (R. id. button2); button2.setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {sendkeycode (keyevent. keycode_dpad_down) ;}}) ;}/ *** enter the required key value * @ Param keycode */private void sendkeycode (final int keycode) {New thread () {public void run () {try {instrumentation inst = new instrumentation (); Inst. sendkeydownupsync (keycode);} catch (exception e) {log. E ("exception when sendpointersync", E. tostring ());}}}. start ();}}
Add permission:
<uses-permission android:name="android.permission.INJECT_EVENTS" />
Very simple. Source code ==>>
Original article, reproduced please indicate the source: http://blog.csdn.net/tangcheng_ OK