The following example describes how to simulate an android dialing device.
AndroidManifest. xml list
<?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 = "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 (). toString ();
// Method 1: Use Intent to activate android Components
// Intent intent = new Intent ();
// Intent. setAction ("android. intent. action. CALL ");
// Intent. setData (Uri. parse ("tel:" + tel ));
// Method 2
Intent intent = new Intent ("android. intent. action. CALL", Uri. parse ("tel:" + tel ));
// The method automatically sets the category for the intent object: android. intent. category. DEFAULT.
StartActivity (intent );
}
});
}
}
Running result:
Interface Initialization
Dialing Effect