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