Android instance-make a phone call

Source: Internet
Author: User

(1) The project structure is as follows:


(2) Mainactivity.java

Package Com.example.phonecall;import Android.app.activity;import Android.content.intent;import Android.net.Uri; Import Android.os.bundle;import android.view.menu;import Android.view.view;import Android.widget.button;import Android.widget.edittext;public class Mainactivity extends Activity {private Button button;private EditText edittext;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); button = (button) This.findviewbyid (r.id.button1); editText = (EditText) This.findviewbyid ( R.ID.EDITTEXT1); Button.setonclicklistener (new Buttonclicklistener ());} Private Final class Buttonclicklistener implements View.onclicklistener {@Overridepublic void OnClick (View v) {String num ber = Edittext.gettext (). toString (); Intent Intent = new Intent ();/* * dial to add dialing permissions in the manifest file */intent.setaction (" Android.intent.action.CALL "), Intent.addcategory (" Android.intent.category.DEFAULT "); Intent.setdata (Uri.parse (" Tel: "+ number"); StartactivitY (Intent);}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

(3)

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" fill_parent "    android:layout_height=" Fill_parent    " android:orientation= "vertical"    tools:context= ". Mainactivity ">    <textview        android:id=" @+id/textview1 "        android:layout_width=" Fill_parent        " android:layout_height= "Wrap_content"        android:text= "Please enter your phone number"/>    <edittext        android:id= "@+id/ EditText1 "        android:layout_width=" match_parent "        android:layout_height=" wrap_content "/>    < Button        android:id= "@+id/button1"        android:layout_width= "wrap_content"        android:layout_height= " Wrap_content "        android:text=" dial "/></linearlayout>


Add permissions to the manifest file:

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



Android instance-make a phone call

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.