Android phone simulation program implementation

Source: Internet
Author: User

*/Simulate a callProgramWhat do we need?

1. Draw the android UI

2. The interface is equipped

In our design on the UI, we found that there are two string strings, one text box and one button.

First add two strings to the res-values-strings.xml

<? XML version = "1.0" encoding = "UTF-8" ?>
< Resources >

< String Name = "Hello" > Hello world, myphoneactivity! </ String >
< String Name = "App_name" > Myphone </ String >
< String Name = "Input_info" > Enter mobile phone number </ String >
< String Name = "Button_caption" > Outbound </ String >
</ Resources >

Then add the layout interface to the res-layout-main.xml

<? XML version = "1.0" encoding = "UTF-8" ?>
< Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Android: layout_width = "Fill_parent"
Android: layout_height = "Fill_parent"
Android: Orientation = "Vertical"   >

<! -- Add textview component -->
< Textview
Android: layout_width = "Fill_parent"
Android: layout_height = "Wrap_content"
Android: Text = "@ String/input_info"   />
<! -- Add edittext component -->
< Edittext Android: layout_width = "Fill_parent"
Android: layout_height = "Wrap_content"
Android: ID = "@ + ID/phone_number"   />
<! -- Add button -->
< Button Android: layout_width = "Wrap_content"
Android: layout_height = "Wrap_content"
Android: Text = "@ String/button_caption"
Android: ID = "@ + ID/dial_btn"   />

</Linearlayout>


OK. The page is set up. What should I do next?

3.

Package CN. class3g. activity;

ImportAndroid. App. activity;
ImportAndroid. content. intent;
ImportAndroid.net. Uri;
ImportAndroid. OS. Bundle;
ImportAndroid. View. view;
ImportAndroid. View. View. onclicklistener;
ImportAndroid. widget. Button;
ImportAndroid. widget. edittext;

/**
* Key points for creating an activity:
* 1. An activity is a class that inherits the activity
* 2. Override the oncreate method.
* 3. Each activity must be in androidmanifest. Configure in XML
* 4. Add necessary controls in Main. xml
*
 */

Public ClassMyphoneactivityExtendsActivity {
//Find the widget
Edittext numberet;
Button dialbtn;

// Override oncreate Method
@ Override
Public Void Oncreate (bundle savedinstancestate ){
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Findviews ();
Dialbtn. setonclicklistener (mylistener );

}
// Retrieve control content
Private Void Findviews (){
Numberet = (edittext) This . Findviewbyid (R. Id. phone_number );
Dialbtn = (button) This . Findviewbyid (R. Id. dial_btn );
}

Private Onclicklistener mylistener = New Button. onclicklistener (){


@ Override
Public Void Onclick (view v ){

// Call the system's dialing service to enable the dialing Function
String phone_number = numberet. gettext (). tostring ();
Phone_number = phone_number.trim ();
If (Phone_number! = Null &&! Phone_number.equals ("")){
// Encapsulate the intent of a call, and package the phone number into a URI object to pass in
Intent intent = New Intent (intent. action_call, Uri. parse ("Tel:" + phone_number ));
Myphoneactivity. This . Startactivity (intent ); // Internal class
}
}

};
}

Can I make a call? Actually, this is not because permissions are still involved. How do I set permissions?

To modify the permission in androidmanifest. XML, you can directly add <uses-Permission Android: Name = "android. Permission. call_phone"/>

You can also use the editor to open

Edit in permission Editor

Select dialing permission

Save it.

Run as-Android Application

If you have a real machine, you can test it directly on the real machine. The test is correct.

If there is no real machine, you can enable two simulators. One is to install the program in the simulator, and the other is to call the simulator number.

The simulator number is 5556.

For example, you can see the Myphone Application

Click to run
Enter 5556 in the input box and click to dial


The implementation of the simulated call program is finished here!
For details about how to run multiple VMS, refer to: Eclipse debugging Android tool highlights: How to run multiple VMS

URL: http://greatverve.cnblogs.com/archive/2012/01/05/android-phone.html

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.