Phone Dialer:
Permissions: Android.permission.CALL_PHONE
Layout code:
< Relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"
xmlns:tools="Http://schemas.android.com/tools"
android:layout_width="Match_parent"
android:layout_height="Match_parent"
Tools:context=". Mainactivity ">
< EditText
android:id="@+id/et_number"
android:layout_width="Match_parent"
android:layout_height="Wrap_content"
android:layout_alignparenttop="true"
android:ems="Ten"
Android:inputtype="Phone">
< Requestfocus />
</ EditText >
< Button
android:id="@+id/bt_dail"
android:layout_width="Wrap_content"
android:layout_height="Wrap_content"
android:layout_alignparentright="true"
Android:layout_below="@id/et_number"
Android:text="@string/dail"/>
</ Relativelayout >
Program code:
Package com.example.dail;
import Android.net.Uri;
import Android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import Android.view.View;
import Android.view.View.OnClickListener;
import Android.widget.Button;
import Android.widget.EditText;
import android.widget.Toast;
Public class Mainactivity extends Activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
Super. OnCreate (savedinstancestate);
// Loading layout Files
Setcontentview (r.layout. Activity_main);
// Find button
Button bt_dail= (button) Findviewbyid (r.id. Bt_dail);
// register a Click event for a button
Bt_dail.setonclicklistener (new MyListener ());
}
Private class MyListener implements Onclicklistener
{
/**
* how the button is clicked
*/
@Override
Public void OnClick (View arg0) {
EditText et_number= (EditText) Findviewbyid (r.id. Et_number);
String Number=et_number.gettext (). toString ();
// determine if the input is empty
if (Textutils. IsEmpty (number))
{
//toast.length_short This information is displayed for one second
Toast. Maketext (Mainactivity. This," number cannot be empty ", Toast. length_short). Show ();
return;
}
// intention to do something
Intent intent=New Intent ();
// the action of the intended counterpart
Intent.setaction (Intent. Action_call);
// the object that performs the action
Intent.setdata (Uri. Parse("Tel:"+number));
// open a new interface to perform this action
StartActivity (Intent);
}
}
}
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
Android Basics (3): Phone Dialer