As we all know, dialing is the most important and commonly used function for a mobile phone.AndroidHow does one implement the dialing procedure? I wrote a simple call hereDemoFor your reference, there are five steps.
Step 1: CreateAndroidProject, namedPhonecalldemo.
Step 2:Design the program interface, openMain. xmlModify the content as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Please input the phonenumer :"
/>
<Edittext
Android: Id = "@ + ID/ET1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: phonenumber = "true"
/>
<Button
Android: Id = "@ + ID/Bt1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "call phone"
/>
</Linearlayout>
Step 3: add the call permission and open androidmanifest. xml. Modify the Code as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Android. test"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". phonecalldemo"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
<Uses-SDK Android: minsdkversion = "3"/>
<! -- Add the dialing permission -->
<Uses-Permission Android: Name = "android. Permission. call_phone">
</Uses-Permission>
</Manifest>
Step 4: The main program phonecalldemo. Java code is as follows:
Package com. Android. test;
Import Android. App. activity;
Import Android. content. intent;
Import android.net. Uri;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. Button;
Import Android. widget. edittext;
Import Android. widget. Toast;
Public class phonecalldemo extends activity {
Private button Bt;
Private edittext et;
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Obtain resources
Bt = (button) findviewbyid (R. Id. Bt1 );
ET = (edittext) findviewbyid (R. Id. ET1 );
// Add Event Response
Bt. setonclicklistener (New button. onclicklistener (){
@ Override
Public void onclick (view v ){
// Obtain the entered phone number string
String inputstr = ET. gettext (). tostring ();
// If the input is not empty, create the intent for the call.
If (inputstr. Trim (). Length ()! = 0)
{
Intent phoneintent = new intent ("android. Intent. Action. Call ",
Uri. parse ("Tel:" + inputstr ));
// Start
Startactivity (phoneintent );
}
// Otherwise, toast prompts
Else {
Toast. maketext (phonecalldemo. This, "cannot be blank", Toast. length_long). Show ();
}
}
});
}
}
Step 5: run the code. The effect is as follows: