Android dialing device
1. Create an android project named javacallPhone and create a CallPhoneActivity. java class under the cn. csdn. hr. activity Package.
2. open main in Layout under res. xml layout, set the layout mode to horizontal layout, and drag the Phone and button under textview, text files on the left, and use the new String button. The effect is as follows:
3.
Open CallPhoneActivity. java and write the code 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 when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Set the displayed View Interface
SetContentView (R. layout. main );
// Obtain the corresponding components in the layout File
Button callBtn = (Button) findViewById (R. id. callBtn );
// Register a click event for the button
CallBtn. setOnClickListener (new View. OnClickListener (){
Public void onClick (View v ){
// Dial
// Get the Editable object in the input box
EditText editText = (EditText) findViewById (R. id. editCallPhone );
// Obtain the entered phone number
Editable editable = editText. getText ();
// Convert to string: editable. toString ();
// Intention
Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel:" + editable. toString ()));
// Execute
StartActivity (intent );
}
});
}
}
4. Open the project list file Andriod Manifest. xml, select permissions, and add the user's call permission, such:
Appears in the source code
<Uses-permission android: name = "android. permission. CALL_PHONE"/>
6. run the as Android Application to implement the dialing function.