Android Phone Dialer Development

Source: Internet
Author: User

1. Create a new Android project called Javacallphone, and build a Callphoneactivity.java class under Cn.csdn.hr.activity package

2. Open the layout under the Res main.xml layout, set the layout of the horizontal layout, and then from the left to drag into the Textview,text files under the Phone, and button buttons, through the new string after the effect is as follows:

3.

Open Callphoneactivity.java to write, the specific code is as follows:

Package cn.csdn.hr.activity;

Import android.app.Activity;

Import android.content.Intent;

Import Android.net.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 the activity is a. */

@Override

public void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Set the view interface for display

Setcontentview (R.layout.main);

Get the appropriate component in the layout file

Button callbtn = (button) Findviewbyid (R.ID.CALLBTN);

Register Click events for buttons

Callbtn.setonclicklistener (New View.onclicklistener () {

public void OnClick (View v) {

Dial

Get an input box to edit an object

EditText EditText = (edittext) Findviewbyid (R.id.editcallphone);

Get the phone number entered

Editable Editable = Edittext.gettext ();

Convert to String: editable.tostring ();

Intention

Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" +editable.tostring ());

Perform

StartActivity (Intent);

}

});

}

}

4. Open the project manifest file andriod manifest.xml, select permissions, add the user call rights, the following figure:

Appearing in source code

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

6, the last run as an Android application, to achieve dial-up 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: 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.