Android mobile phone Call Development example

Source: Internet
Author: User

The most common function of a mobile phone is to call and send text messages, how do we make calls through the program in Android development? This article gives a simple example of making a phone call using an Android phone.

Here are the specific steps to develop this instance:

First, a new Android project, named Phonecalldemo.

Second, design the interface of the program, open main.xml to modify the content as follows:

xml/html Code
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2.   <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.   android:orientation="Vertical"
  4.   Android:layout_width="Fill_parent"
  5.   android:layout_height="Fill_parent"
  6.   >
  7.   <TextView
  8.   Android:layout_width="Fill_parent"
  9.   android:layout_height="Wrap_content"
  10.   android:text="Please input the Phonenumer:"
  11.   />
  12.   <EditText
  13.   android:id="@+id/et1"
  14.   Android:layout_width="Fill_parent"
  15.   android:layout_height="Wrap_content"
  16.   android:phonenumber="true"
  17.   />
  18.   <Button
  19.   android:id="@+id/bt1"
  20.   Android:layout_width="Wrap_content"
  21.   android:layout_height="Wrap_content"
  22.   android:text="Call Phone"
  23.   />
  24.   </linearlayout>

Third, increase the access to call, open Androidmanifest.xml, modify the code as follows:

xml/html Code
  1.  <? XML version= "1.0" encoding="Utf-8"?>
  2.   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.   package="Com.android.test"
  4.   android:versioncode="1"
  5.   Android:versionname="1.0">
  6.   <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.   <activity android:name=". Phonecalldemo "
  8.   Android:label="@string/app_name">
  9.   <intent-filter>
  10.   <action android:name="Android.intent.action.MAIN" />
  11.   <category android:name="Android.intent.category.LAUNCHER" />
  12.   </intent-filter>
  13.   </activity> </application>
  14.   <uses-sdk android:minsdkversion="3" />
  15.   <uses-permission android:name="Android.permission.CALL_PHONE">
  16.   </uses-permission>
  17.   </manifest>

Four, the main program Phonecalldemo.java code is as follows:

Java code
  1. Package com.android.test;   import android.app.Activity;
  2.   Import android.content.Intent;
  3.   Import Android.net.Uri;
  4.   Import Android.os.Bundle;
  5.   Import Android.view.View;
  6.   Import Android.widget.Button;
  7.   Import Android.widget.EditText;
  8.   Import Android.widget.Toast;
  9. public class Phonecalldemo extends Activity {
  10.   Private Button BT;
  11.   Private EditText et;
  12.   Public void OnCreate (Bundle savedinstancestate) {
  13.   Super.oncreate (savedinstancestate);
  14. Setcontentview (R.layout.main);
  15.   Access to resources
  16. BT = (Button) Findviewbyid (R.ID.BT1);
  17. ET = (EditText) Findviewbyid (R.ID.ET1);
  18.   Increase incident Response
  19. Bt.setonclicklistener (new Button.onclicklistener () { @Override
  20.   Public void OnClick (View v) {
  21.   Get the input phone string
  22. String inputstr = Et.gettext (). toString ();
  23.   If the input is not empty create a call intent
  24.   if (Inputstr.trim (). Length ()! =0)
  25. {
  26. Intent phoneintent = new Intent ("Android.intent.action.CALL",
  27. Uri.parse ("Tel:" + inputstr));
  28.   Start
  29. StartActivity (phoneintent);
  30. }
  31.   Otherwise, Toast prompts
  32.   else{
  33. Toast.maketext (Phonecalldemo.   This, "cannot be entered as empty", Toast.length_long). Show ();
  34. }
  35. }
  36. });
  37. }

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.