Call the phone to learn how to use intent.
Because it is a small program, you can use the UI interface> Activity> business layer to write code from top to bottom.
To use system functions, add <uses-permission android: name = "android. permisson. CALL_PHONE"/> to AndroidMainfest. xml.
1. Interface Design res/layout/main. xml
Main. xml
<?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="@string/textMobileString"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:hint="@string/edtMobileNumString"
android:id="@+id/edtMobileNum"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/btnCall"
android:text="@string/btnCallString"/>
</LinearLayout>
2. Add res/values/strings. xml to the string variable
Strings. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello World, PhoneCallActivity! </String>
<String name = "app_name"> PhoneCall </string>
<String name = "textMobileString"> enter the phone number you want to call: </string>
<String name = "edtMobileNumString"> enter the number... </string>
<String name = "btnCallString"> call </string>
</Resources>
3. Compile the Activity
PhoneCallActivity. java
Package com. PhoneCall. melody;
Import android. app. Activity;
Import android. content. Intent;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Public class PhoneCallActivity extends Activity implements OnClickListener {
Private EditText editText = null; // number editing Control
Private Button btnCall = null; // call the Button
Private String mobileNum = null; // number variable
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. main );
/**
* Get controls
*/
EditText = (EditText) this. findViewById (R. id. edtMobileNum );
BtnCall = (Button) this. findViewById (R. id. btnCall );
MobileNum = editText. getText (). toString (); // get the number
BtnCall. setOnClickListener (this); // sets the listener event
}
@ Override
Public void onClick (View v ){
Switch (v. getId ()){
/**
* Call
*/
Case R. id. btnCall:
/**
* Intent. ACTION_CALL -- notifies the System of the intent (Intent) action.
* Uri. parse ("tel:" + mobileNum) Uri is a unified resource identifier, and the phone number is followed by the tel notification system.
*/
Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel :"
+ MobileNum ));
PhoneCallActivity. this. startActivity (intent );
Break;
Default:
Break;
}
}
}