For more information and videos, see the call video of Chuanzhi podcast.
I. layout file: first, design a simple interface for the dial. You can use the drawing software to design the interface.
2. Obtain the phone number in edittext in the activity, click it, and use intent (intent) to implement the call function.
Intent intent = new intent (intent. action_call, Uri. parse ("Tel:" + mobile ));
3: You must set the permission to call in the androidmanifset and XML files.
Core source code (self-cited package)
Public class phoneduanxinactivity extends activity {<br/> private edittext mobiletext; // write a member variable here, you can directly call </P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> mobiletext = (edittext) This. findviewbyid (R. id. mobile); // call the member variable mobiletext to the right </P> <p> // use the Anonymous class to add a listener <br/> button = (button) This. Findviewbyid (R. id. button); <br/> button. setonclicklistener (new view. onclicklistener () {<br/> Public void onclick (view v) {</P> <p> string mobile = mobiletext. gettext (). tostring (); // get the mobile phone number entered by the user <br/> intent = new intent (intent. action_call, Uri. parse ("Tel:" + mobile); // intent (behavior, behavior data) intent class is used to describe what an application will do in WINDOS there is something to start menu, run, http://www.baidu.com it can open directly, why? The browser recognizes http: <br/> startactivity (intent); // This is an instance of the internal class to access the external class <br/>}< br/> }); <br/>}< br/>}
Strings. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <resources> <br/> <string name = "hello"> Good afternoon </string> <br/> <string name = "app_name"> Motorola phone dial </string> <br/> <string name = "mobile"> enter a number </string> <br/> <string name = "button"> call </string> <br/> </resources> <br/>
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> </P> <p> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/mobile" <br/> <edittext <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: Id = "@ + ID/mobile" <br/> <button <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/button" <br/> Android: id = "@ + ID/button" <br/>
These three controls are placed vertically, so you need to use a linear layout to hold the Display Control
:
</Linearlayout>
In fact, the most important thing here is permission settings, call permissions, and understanding intent (behavior, behavior data) usage.