1. Create a new Android project called Javacallphone, and build a Callphoneactivity.java class under Cn.csdn.hr.activity package
2. Open the layout under the Res main.xml layout, set the layout of the horizontal layout, and then from the left to drag into the Textview,text files under the Phone, and button buttons, through the new string after the effect is as follows:
3.
Open Callphoneactivity.java to write, the specific code is as follows:
Package cn.csdn.hr.activity;
Import android.app.Activity;
Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import android.text.Editable;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;
public class Callphoneactivity extends activity {
/** called the activity is a. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Set the view interface for display
Setcontentview (R.layout.main);
Get the appropriate component in the layout file
Button callbtn = (button) Findviewbyid (R.ID.CALLBTN);
Register Click events for buttons
Callbtn.setonclicklistener (New View.onclicklistener () {
public void OnClick (View v) {
Dial
Get an input box to edit an object
EditText EditText = (edittext) Findviewbyid (R.id.editcallphone);
Get the phone number entered
Editable Editable = Edittext.gettext ();
Convert to String: editable.tostring ();
Intention
Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" +editable.tostring ());
Perform
StartActivity (Intent);
}
});
}
}
4. Open the project manifest file andriod manifest.xml, select permissions, add the user call rights, the following figure:
Appearing in source code
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
6, the last run as an Android application, to achieve dial-up function