Android to make phone calls function _android

Source: Internet
Author: User

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

The following are the steps to develop this instance:

One, 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

<?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:layout_width= "fill_parent" 
 
android:layout_ height= "Wrap_content" 
 
android:text= "please input the Phonenumer:" 
 
/> 
 
<edittext 
 
D= "@+id/et1" 
 
android:layout_width= "fill_parent" 
 
android:layout_height= "Wrap_content" 
 
android: Phonenumber= "true" 
 
/> 
 
<button android:id= @+id/bt1 "android:layout_width=" 
 
wrap_ Content " 
 
android:layout_height=" wrap_content " 
 
android:text=" call Phone " 
 
/> 
 

Third, increase the access to the telephone, open androidmanifest.xml, modify the code as follows:

xml/html Code

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= 
 
"http://schemas.android.com/apk/res/" Android " 
 
package=" com.android.test " 
 
android:versioncode=" 1 " 
 
android:versionname=" 1.0 "> 
 
< Application android:icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name= 
 
". Phonecalldemo " 
 
android:label=" @string/app_name "> 
 
<intent-filter> 
 
<action android:name="  Android.intent.action.MAIN "/> 
 
<category android:name=" Android.intent.category.LAUNCHER "/>" 
 
</intent-filter> 
 
</activity> </application> 
 
<uses-sdk android:minsdkversion= "3"/ >  
 
<uses-permission android:name= "Android.permission.CALL_PHONE" > 
 
</uses-permission> 
 

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

 Package Com.android.test;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;
 
 Import Android.widget.Toast; 
 
  public class Phonecalldemo extends activity {private Button BT; 
 
  Private EditText et; 
 
  public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
 
  Setcontentview (R.layout.main); 
 
  Obtain Resources BT = (Button) Findviewbyid (R.ID.BT1); 
 
  ET = (edittext) Findviewbyid (R.ID.ET1); Add Event Response Bt.setonclicklistener (new Button.onclicklistener () {@Override public void OnClick (View v) {//Get input 
 
  The phone number string inputstr = Et.gettext (). toString (); If the input is not empty create a call Intent if (Inputstr.trim (). Length ()!=0) {Intent phoneintent = new Intent ("Android.intent.act Ion. 
 
  Call ", Uri.parse (" Tel: "+ inputstr)); Start StartactiviTy (phoneintent); 
 
  //Otherwise Toast prompts else{toast.maketext (phonecalldemo.this, "cannot enter blank", Toast.length_long). Show (); 
 
  }   }   });  }

Above is the Android development call Simple example, follow-up continue to supplement the relevant information, thank you for your support for this site!

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.