Android Application dialing

Source: Internet
Author: User

 

Last time, we made a simple hello world. This time, we wrote a telephone call system. In fact, this call is not really called by our own program, instead, call the system program.

First, create the project Phone and create the required string under the project's alues à strings.

 

<String name = "app_name"> Phone </string>

 

<String name = "input_info"> enter the number </string>

 

<String name = "dial_caotion"> call </string>

 

 

Create an interface in layout à main. xml

 

<TextView

 

Android: layout_width = "fill_parent"

 

Android: layout_height = "wrap_content"

 

Android: text = "@ string/input_info"/>

 

 

 

<EditText

 

Android: layout_width = "fill_parent"

 

Android: layout_height = "wrap_content"

 

Android: id = "@ + id/phone_number"

 

/>

 

<Button

 

Android: layout_width = "wrap_content"

 

Android: layout_height = "wrap_content"

 

Android: id = "@ + id/dial_btn"

 

Android: text = "@ string/dial_caotion"

 

/>

 

 

This program uses a total of input boxes and buttons, and the text will not be repeated. The rest is our java code.

We need to write the implementation code in src à PhoneActvity. First, we should first obtain the phone number entered by the user in the input box, and then write a listener internal class to listen to button events, the specific implementation code is as follows:

 

NumberEt = (EditText) this. findViewById (R. id. phone_number );

 

DialBtn = (Button) this. findViewById (R. id. dial_btn );

 

 

 

DialBtn. setOnClickListener (new OnClickListener (){

 

 

@ Override

 

Public void onClick (View v ){

 

// TODO Auto-generated method stub

 

// Call the dialing service of the system to enable the dialing Function

 

String phone_number = numberEt. getText (). toString ();

 

Phone_numberphone_number = phone_number.trim ();

 

If (phone_number! = Null &&! Phone_number.equals ("")){

 

// Encapsulate a call intent and package the phone number into a Uri object

 

Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel:" + phone_number ));

 

PhoneActivity. this. startActivity (intent );

 

}

 

}

 

});

 

From chenglong0513

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.