[Android Application Development]-(20) simple analog button to send messages

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.