Android phone number dialing development instance, android phone number dialing
The most common function of a mobile phone is to call and send text messages. In Android development, how do we call the phone through a program? This article provides a simple example of using an Android mobile phone to call.
The steps for developing this instance are as follows:
1. Create an Android project named phoneCallDemo.
2. Open the main. xml interface to modify the content as follows:
XML/HTML code
- <? 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 = "Please input the phoneNumer :"
- />
- <EditText
- Android: id = "@ + id/et1"
- Android: layout_width = "fill_parent"
- Android: layout_height = "wrap_content"
- Android: phoneNumber = "true"
- />
- <Button
- Android: id = "@ + id/bt1"
- Android: layout_width = "wrap_content"
- Android: layout_height = "wrap_content"
- Android: text = "Call Phone"
- />
- </LinearLayout>
3. Add the call permission and open AndroidManifest. xml. Modify the Code as follows:
XML/HTML code
- <? Xml version = "1.0" encoding = "UTF-8"?>
- <Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
- Package = "com. android. test"
- Android: versionCode = "1"
- Android: versionName = "1.0" type = "codeph" text = "/codeph">
- <Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
- <Activity android: name = ". PhoneCallDemo"
- 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 = "3"/>
- <Uses-permission android: name = "android. permission. CALL_PHONE">
- </Uses-permission>
- </Manifest>
4. The main program phoneCallDemo. java code is as follows:
Java code
- Package com. android. test; 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;
- Import android. widget. Toast;
-
- Public class PhoneCallDemo extends Activity {
- Private Button bt;
- Private EditText et;
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. main );
- // Obtain resources
- Bt = (Button) findViewById (R. id. bt1 );
- Et = (EditText) findViewById (R. id. et1 );
- // Add Event Response
- Bt. setOnClickListener (new Button. OnClickListener () {@ Override
- Public void onClick (View v ){
- // Obtain the entered phone number string
- String inputStr = et. getText (). toString ();
- // If the input is not empty, create the Intent for the call.
- If (inputStr. trim (). length ()! = 0)
- {
- Intent phoneIntent = new Intent ("android. intent. action. CALL ",
- Uri. parse ("tel:" + inputStr ));
- // Start
- StartActivity (phoneIntent );
- }
- // Otherwise, Toast prompts
- Else {
- Toast. makeText (PhoneCallDemo. this, "cannot be blank", Toast. LENGTH_LONG). show ();
- }
- }
- });
- }
Android Development Instance source code
API demo, but no remote database
Teaching blogs are basic things. They are nothing more than how to use APIs.
In eclipse android development, a mobile phone interface is implemented. You can call a phone call directly. If you can call a phone call, how can you do this?
It is best to use a real machine to test the call permission added to the list file; if not, you can test two simulators.