Basic Android tutorial-simple dialing program !!!

Source: Internet
Author: User

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:

 

 

 

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.