Method One,
1. Create a Callphone project
2. Add the configuration of the text name to the String.xml file
3. Adding controls to the Activity_phone.xml file
4. Add dialing-related code in Phoneactivity.java
5. Run the code and discover that the following error occurred
Cause of error: No dialing permissions added
Add a permission configuration in Callphone Manifest (androidmanifest.xml)
6. Run the code with the following results
7. Summary
Method Two,
Public class PhoneActivity2 extends Activity {
Private EditText Etphone;
Private Button callbtn;
@Override
protected void onCreate (Bundle savedinstancestate) {
Super. OnCreate (savedinstancestate);
Setcontentview (r.layout. Activity_phone);
Etphone= (EditText) Findviewbyid (r.id. Etphone);
CALLBTN = (Button) Findviewbyid (r.id. Callbtn);
Callbtn.setonclicklistener (new Onclicklistener () {
@Override
Public void OnClick (View v) {
1. Get the dialed phone number
String Phone=etphone.gettext (). toString ();
Toast effect
Toast. Maketext (PhoneActivity2. This, "Dial-up" +phone, Toast. Length_long). Show ();
2. Define the intent of dialing
Intent intent=New Intent (Intent. Action_call, Uri. Parse ("Tel:" +phone));
3. intention to perform dialing
StartActivity (Intent);
}
});
}
}
android--Simple phone dialing function