In this example, the Intent (Intent) is used to call the system dialer to call the phone.
1. layout File
Android: hint = "@ string/phoneHint": indicates the hidden prompt information.
Android: inputType = "phone": indicates that the input type is phone number.
android:hint="@string/phoneHint" android:ems="10"
android:inputType="phone" >
2. MainActivity
Set button listening events
Intent. setData (Uri. parse ("tel:" + phoneNumber): sets the data to be transmitted. The Uri type. The telephone number must be prefixed with "tel :"
Intent. setAction (Intent. ACTION_CALL): sets the Intent action to call.
A similar feature is available in Windows, where you enter the start http://www.baidu.com in the command line, which will be opened in the default browser.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHByZSBjbGFzcz0 = "brush: java;"> public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); (Button) findViewById (R. id. btnCall )). setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {String phoneNumber = (EditText) findViewById (R. id. etPhone )). getText (). toString (); // intention: Intent intent = new Intent (); intent. setAction (Intent. ACTION_CALL); // url: Uniform Resource Locator // uri: Uniform Resource Identifier (WIDER) intent. setData (Uri. parse ("tel:" + phoneNumber); // enable the system dial startActivity (intent );}});}}3. An error is reported. If you do not have the permission to run the program, the following error is found in LogCat:
03-22 16:58:47. 263: E/AndroidRuntime (26347): java. lang. securityException: Permission Denial: starting Intent {act = android. intent. action. CALL dat = tel: xxx cmp = com. android. phone /. outgoingCallBroadcaster} from ProcessRecord {41eec660 26347: com. example. call/u0a77} (pid = 26347, uid = 10077) requires android. permission. CALL_PHONE
Add the android. permission. CALL_PHONE permission to AndroidManifest. xml.
Running effect: