1. telephone dial

Source: Internet
Author: User

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

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.