Android calls-use intent and androidmanifset. XML to add permissions

Source: Internet
Author: User

For more information and videos, see the call video of Chuanzhi podcast.

 

 

I. layout file: first, design a simple interface for the dial. You can use the drawing software to design the interface.

2. Obtain the phone number in edittext in the activity, click it, and use intent (intent) to implement the call function.

Intent intent = new intent (intent. action_call, Uri. parse ("Tel:" + mobile ));

 

3: You must set the permission to call in the androidmanifset and XML files.

 

 

Core source code (self-cited package)

 

Public class phoneduanxinactivity extends activity {<br/> private edittext mobiletext; // write a member variable here, you can directly call </P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> mobiletext = (edittext) This. findviewbyid (R. id. mobile); // call the member variable mobiletext to the right </P> <p> // use the Anonymous class to add a listener <br/> button = (button) This. Findviewbyid (R. id. button); <br/> button. setonclicklistener (new view. onclicklistener () {<br/> Public void onclick (view v) {</P> <p> string mobile = mobiletext. gettext (). tostring (); // get the mobile phone number entered by the user <br/> intent = new intent (intent. action_call, Uri. parse ("Tel:" + mobile); // intent (behavior, behavior data) intent class is used to describe what an application will do in WINDOS there is something to start menu, run, http://www.baidu.com it can open directly, why? The browser recognizes http: <br/> startactivity (intent); // This is an instance of the internal class to access the external class <br/>}< br/> }); <br/>}< br/>}

Strings. xml

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <resources> <br/> <string name = "hello"> Good afternoon </string> <br/> <string name = "app_name"> Motorola phone dial </string> <br/> <string name = "mobile"> enter a number </string> <br/> <string name = "button"> call </string> <br/> </resources> <br/>

Main. xml

 

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> </P> <p> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/mobile" <br/> <edittext <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: Id = "@ + ID/mobile" <br/> <button <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/button" <br/> Android: id = "@ + ID/button" <br/>

These three controls are placed vertically, so you need to use a linear layout to hold the Display Control

:

</Linearlayout>

 

In fact, the most important thing here is permission settings, call permissions, and understanding intent (behavior, behavior data) usage.

 

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.