Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Hello" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/inputphonenumber" <br/> <edittext <br/> Android: id = "@ + ID/phonenumber" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: phonenumber = "true" <br/> <button <br/> Android: Id = "@ + ID/btn_call" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/call" <br/> </linearlayout>
Androidmanifest. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. wide. phone "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <uses-SDK Android: minsdkversion = "8"/> <br/> <! -- Add the permission to make outgoing calls --> <br/> <uses-Permission Android: Name = "android. permission. call_phone "> </uses-Permission> <br/> <application Android: icon =" @ drawable/icon "Android: label = "@ string/app_name"> <br/> <activity Android: Name = ". phoneacitivity "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> </Application> <br/> </manifest>
Phoneactivity. Java
Package COM. wide. phone; <br/> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android.net. uri; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. widget. button; <br/> Import android. widget. edittext; <br/> public class phoneacitivity extends activity {<br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> button btn_call = (button) findviewbyid (R. id. btn_call); </P> <p> btn_call.setonclicklistener (New onclicklistener () {<br/> Public void onclick (view V) {<br/> // todo auto-generated method stub <br/> edittext et_phonenumber = (edittext) findviewbyid (R. id. phonenumber); <br/> string number = et_phonenumber.gettext (). tostring (); <br/> // start to call with intent <br/> intent = new intent (intent. action_call, Uri. parse ("Tel:" + number); <br/> startactivity (intent); <br/>}< br/> }); <br/>}< br/>}