One, telephone dialer

Source: Internet
Author: User

The following example simulates the implementation of an Android Phone Dialer

Androidmanifest.xml List of 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"/>

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:text= "Please enter your phone number"/>
<edittext android:layout_width= "Fill_parent"

Android:id= "@+id/phone"/>
<button android:layout_width= "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 (). toString ();
Method one, use intent Purpose: activate Android components
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 inside of the method automatically sets the category for the intent object: Android.intent.category.DEFAULT
StartActivity (Intent);
}
});
}
}

Operation Result:

Interface initialization

Telephone dialing Effect

One, telephone dialer

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.