Android's second app-Phone Dialer

Source: Internet
Author: User

I. below

II,

Because the app wants to use the mobile phone service, you need to add the telephone service permission in the androidmanifest. xml file of the list file:

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "cn. itcast. Action"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
....
<Uses-SDK Android: minsdkversion = "6"/>
<Uses-Permission Android: Name = "android. Permission. call_phone"/>
</Manifest>

3. layout Interface

Interface layout:
<? 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 = "@ string/inputmobile"/>

<Edittext Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"
Android: Id = "@ + ID/mobile"/>

<Button Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"
Android: text = "@ string/button"
Android: Id = "@ + ID/button"/>
</Linearlayout>

Linearlayout (linear layout), absolutelayout (absolute layout), relativelayout (relative layout), tablelayout (table layout), framelayout (frame layout)

4. Code in the phoneactivity class:

Package COM. example. lession01_phone; import android.net. uri; import android. OS. bundle; import android. app. activity; import android. content. intent; import android. view. menu; import android. view. view; import android. widget. button; import android. widget. edittext; import android. widget. toast; public class phoneactivity extends activity {private edittext; private button button_phone; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // set to display pyltsetcontentview (R. layout. activity_phone); // obtain the button component button_phone = (button) findviewbyid (R. id. phone_button); // obtain the input box component edittext = (edittext) findviewbyid (R. id. phone_text); // register the button event button_phone.setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stub // obtain the number string phone_num = edittext. gettext (). tostring (); // defines the intent object intent = new intent (intent. action_call, Uri. parse ("Tel:" + phone_num); // execute the intent phoneactivity. this. startactivity (intent); // toast of toast. maketext (phoneactivity. this, "calling" + phone_num + ", toast. length_long ). show () ;}}) ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. phone, menu); Return true ;}}

5. Test Procedure

Test procedure:
1> run this application in eclipse
2> in the DOS window, go to the tools directory of the android SDK installation path, and run the following command to enable an android simulator:
Emulator-data itcast
Note: itcast is a user data access file. If the file does not exist, the file is created in the tools directory by default.

3> enter the displayed phone number in the phone contact list.

 

 

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.