Android phone number dialing development instance, android phone number dialing

Source: Internet
Author: User

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
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
  3. Android: orientation = "vertical"
  4. Android: layout_width = "fill_parent"
  5. Android: layout_height = "fill_parent"
  6. >
  7. <TextView
  8. Android: layout_width = "fill_parent"
  9. Android: layout_height = "wrap_content"
  10. Android: text = "Please input the phoneNumer :"
  11. />
  12. <EditText
  13. Android: id = "@ + id/et1"
  14. Android: layout_width = "fill_parent"
  15. Android: layout_height = "wrap_content"
  16. Android: phoneNumber = "true"
  17. />
  18. <Button
  19. Android: id = "@ + id/bt1"
  20. Android: layout_width = "wrap_content"
  21. Android: layout_height = "wrap_content"
  22. Android: text = "Call Phone"
  23. />
  24. </LinearLayout>

3. Add the call permission and open AndroidManifest. xml. Modify the Code as follows:

XML/HTML code
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
  3. Package = "com. android. test"
  4. Android: versionCode = "1"
  5. Android: versionName = "1.0" type = "codeph" text = "/codeph">
  6. <Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
  7. <Activity android: name = ". PhoneCallDemo"
  8. Android: label = "@ string/app_name">
  9. <Intent-filter>
  10. <Action android: name = "android. intent. action. MAIN"/>
  11. <Category android: name = "android. intent. category. LAUNCHER"/>
  12. </Intent-filter>
  13. </Activity> </application>
  14. <Uses-sdk android: minSdkVersion = "3"/>
  15. <Uses-permission android: name = "android. permission. CALL_PHONE">
  16. </Uses-permission>
  17. </Manifest>

4. The main program phoneCallDemo. java code is as follows:

Java code
  1. Package com. android. test; import android. app. Activity;
  2. Import android. content. Intent;
  3. Import android.net. Uri;
  4. Import android. OS. Bundle;
  5. Import android. view. View;
  6. Import android. widget. Button;
  7. Import android. widget. EditText;
  8. Import android. widget. Toast;
  9.  
  10. Public class PhoneCallDemo extends Activity {
  11. Private Button bt;
  12. Private EditText et;
  13. Public void onCreate (Bundle savedInstanceState ){
  14. Super. onCreate (savedInstanceState );
  15. SetContentView (R. layout. main );
  16. // Obtain resources
  17. Bt = (Button) findViewById (R. id. bt1 );
  18. Et = (EditText) findViewById (R. id. et1 );
  19. // Add Event Response
  20. Bt. setOnClickListener (new Button. OnClickListener () {@ Override
  21. Public void onClick (View v ){
  22. // Obtain the entered phone number string
  23. String inputStr = et. getText (). toString ();
  24. // If the input is not empty, create the Intent for the call.
  25. If (inputStr. trim (). length ()! = 0)
  26. {
  27. Intent phoneIntent = new Intent ("android. intent. action. CALL ",
  28. Uri. parse ("tel:" + inputStr ));
  29. // Start
  30. StartActivity (phoneIntent );
  31. }
  32. // Otherwise, Toast prompts
  33. Else {
  34. Toast. makeText (PhoneCallDemo. this, "cannot be blank", Toast. LENGTH_LONG). show ();
  35. }
  36. }
  37. });
  38. }

 


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.
 

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.