Implementation of a simple phone call program for Android _ student originality

Source: Internet
Author: User
Implementation of a simple phone call program for Android

Step 1: Interface Design

Step 2: overall implementation:

Phone call is the main function of mobile phones. The first program in Android is to implement the call function.

1. First, add the corresponding text information to strings. XML in the values directory.

<String name = "input_info"> enter the number you want to call: </string> <string name = "dial_caption"> call </string>

2. Implement the page layout in layout and introduce the corresponding text information.

<! -Insert the page title --> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/input_info"/> <! -Define the text box --> <edittext Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Id = "@ + ID/phone_number"/> <! -Define a button --> <button Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Id = "@ + ID/dial_btn" Android: TEXT = "@ string/dial_caption"/>

3. Write Java code:

Import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. edittext; Public classphoneactivity extends activity {// define the text box and button edittext numberet; button dialbtn; publicvoidoncreate (bundle savedinstancestate) {super. oncreate (savedinstancest Ate); setcontentview (R. layout. main); findviews (); dialbtn. setonclicklistener (New onclicklistener () {public void onclick (view v) {// call the dialing service of the system to implement the dialing function stringphone_number = numberet. gettext (). tostring (); phone_number = phone_number.trim (); If (phone_number! = NULL &&! Phone_number.equals ("") {// encapsulate the intent of a call and package the phone number into a URI object to pass in intentintent = newintent (intent. action_call, Uri. parse ("Tel:" + phone_number); phoneactivity. this. startactivity (intent) ;}});} public void findviews () {numberet = (edittext) This. findviewbyid (R. id. phone_number); dialbtn = (button) This. findviewbyid (R. id. dial_btn );}}

4. Don't forget to grant it the permission to write in androidmanifest. xml.

<uses-permission android:name="android.permission.CALL_PHONE"/>

5. Start the simulator twice and simulate 5556 to call 5554.

Test in the android virtual machine as shown in the following figure:

 

The above is a simple call implementation. I hope you can understand it!

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.