How do I call the phone in Android?

Source: Internet
Author: User

The Android system was originally designed for mobile phones, so it's very convenient to make a designated phone call in any app in the Android system.
The core is to use the intent jump, specifying that the request ACTION is Intent.action_call.

"Source Download" http://www.code4apk.com/android-code/178


The core code is as follows:

1 intent Intent =  new intent (Intent.action_call,uri.parse (" tel:13888888888 ");

This is accomplished by:

1th Step: Create a new activity:dialerandmsgactivity

package Com.android.dev;import android.app.Activity; Import android.content.Intent; Import Android.net.Uri; Import Android.os.Bundle; Import Android.view.View; Import Android.widget.Button; Import Android.widget.edittext;public class Dialerandmsgactivity extends Activity {private Button Dialerbutton; private EditText edittextphonenum;/** Called when the activity is first created. */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.main);d Ialerbutton = (Button) Findviewbyid (R.id.button_dialer); Edittextphonenum = (EditText) Findviewbyid (r.id.edittext_phonenum);d Ialerbutton.setonclicklistener (new View.onclicklistener () {public void OnClick (View arg0) {Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" + Edittextphonenum.gettext ())); DialerAndMsgActivity.this.startActivity (Intent); }}); } }


2nd Step: Modify the configuration file: Main.xml

<?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:id= "@+id/textview_phone" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content "android:text=" @string/tell_tile "/><edittext android:id=" @+id/edittext_phonenum "Android:layout_ Width= "Fill_parent" android:layout_height= "wrap_content"/> <button android:id= "@+id/Button_Dialer" Android: Layout_width= "100DP" android:layout_height= "wrap_content" android:text= "@string/button_call"/> </ Linearlayout>

3rd Step: Add dial-up support in configuration file Androidmanifest.xml

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

4th Step Debug Run:

Android Phone Call

Android Phone Call

"Source Download" http://www.code4apk.com/android-code/178

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.