Android development Android dialing device

Source: Internet
Author: User

Android dialing device
1. Create an android project named javacallPhone and create a CallPhoneActivity. java class under the cn. csdn. hr. activity Package.

2. open main in Layout under res. xml layout, set the layout mode to horizontal layout, and drag the Phone and button under textview, text files on the left, and use the new String button. The effect is as follows:



Open CallPhoneActivity. java and write the code as follows:

Package cn. csdn. hr. activity;

Import android. app. Activity;

Import android. content. Intent;

Import Uri;

Import android. OS. Bundle;

Import android. text. Editable;

Import android. view. View;

Import android. widget. Button;

Import android. widget. EditText;

Public class CallPhoneActivity extends Activity {

/** Called when the activity is first created .*/

@ Override

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

// Set the displayed View Interface

SetContentView (R. layout. main );

// Obtain the corresponding components in the layout File

Button callBtn = (Button) findViewById (R. id. callBtn );

// Register a click event for the button

CallBtn. setOnClickListener (new View. OnClickListener (){

Public void onClick (View v ){

// Dial

// Get the Editable object in the input box

EditText editText = (EditText) findViewById (R. id. editCallPhone );

// Obtain the entered phone number

Editable editable = editText. getText ();

// Convert to string: editable. toString ();

// Intention

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

// Execute

StartActivity (intent );






4. Open the project list file Andriod Manifest. xml, select permissions, and add the user's call permission, such:

Appears in the source code

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

6. run the as Android Application to implement the dialing function.


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: 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.