(1) The project structure is as follows:
(2) Mainactivity.java
Package Com.example.phonecall;import Android.app.activity;import Android.content.intent;import Android.net.Uri; Import Android.os.bundle;import android.view.menu;import Android.view.view;import Android.widget.button;import Android.widget.edittext;public class Mainactivity extends Activity {private Button button;private EditText edittext;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); button = (button) This.findviewbyid (r.id.button1); editText = (EditText) This.findviewbyid ( R.ID.EDITTEXT1); Button.setonclicklistener (new Buttonclicklistener ());} Private Final class Buttonclicklistener implements View.onclicklistener {@Overridepublic void OnClick (View v) {String num ber = Edittext.gettext (). toString (); Intent Intent = new Intent ();/* * dial to add dialing permissions in the manifest file */intent.setaction (" Android.intent.action.CALL "), Intent.addcategory (" Android.intent.category.DEFAULT "); Intent.setdata (Uri.parse (" Tel: "+ number"); StartactivitY (Intent);}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
(3)
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" fill_parent " android:layout_height=" Fill_parent " android:orientation= "vertical" tools:context= ". Mainactivity "> <textview android:id=" @+id/textview1 " android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:text= "Please enter your phone number"/> <edittext android:id= "@+id/ EditText1 " android:layout_width=" match_parent " android:layout_height=" wrap_content "/> < Button android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= " Wrap_content " android:text=" dial "/></linearlayout>
Add permissions to the manifest file:
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
Android instance-make a phone call