How to implement the Android Phone Dialer _android

Source: Internet
Author: User

This example describes the implementation of the Android Phone Dialer. Share to everyone for your reference. Specifically as follows:

The following cases simulate the implementation of the Android Phone Dialer

List of Androidmanifest.xml lists

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
  package=" Com.ljq.phone "
  android:versioncode=" 1 "
  android:versionname=" 1.0 ">
 < Application android:icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name=
  ". Mainactivity "
     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 = "7"/>
 <uses-permission android:name= "Android.permission.CALL_PHONE"/>
</manifest>

Main.xml Layout file:

<?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 enter the phone number"/>
 <edittext android:layout_width= "fill_parent"
  android:layout_height= "Wrap_content" 
  android:id= "@+id/phone"/>
 <button android:layout_width= "Wrap_content"
  android:layout_height= "Wrap_content" 
  android:text= "dial this number"
  android:id= "@+id/button"/> </
Linearlayout>

Mainactivity class:

Package com.ljq.phone;
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 Mainactivity extends activity {private EditText phone=null;
  @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.layout.main);
  Phone= (EditText) This.findviewbyid (R.id.phone);
  Button button= (button) This.findviewbyid (R.id.button); Button.setonclicklistener (New View.onclicklistener () {public void OnClick (View v) {String tel=phone.gettext (). toSt
    Ring ();
    Method one, using Intent purpose: To activate the Android component//intent intent=new Intent ();
    Intent.setaction ("Android.intent.action.CALL");
    Intent.setdata (Uri.parse ("Tel:" +tel));
    Method two Intent intent=new Intent ("Android.intent.action.CALL", Uri.parse ("Tel:" +tel)); The interior of the method automatically sets the category for the intent object: Android.intent.category.DEFAULT startactIvity (Intent);
 }
  });

 }
}

Run Result:

Interface initialization:

Phone Dialing effect:

I hope this article will help you with your Android program.

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.