1.因为应用要使用手机的电话服务,所以要在清单文件AndroidManifest.xml中添加电话服务权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
2.在界面中button的onClick事件的代码:
EditText text = (EditText)findViewById(R.id.mobile);
String mobile=text.getText().toString();//取得号码
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+mobile));
startActivity(intent);//这句与XXXX.this.startActivity(intent)等价
拓展知识:
1.其中//"android.intent.action.CALL"等价于Intent.ACTION_CALL
因为在android代码ACTION_CALL里面装的是"android.intent.action.CALL"这个字符串
常用Action动作:
ACTION_CALL activity Initiate a phone call.
ACTION_EDIT activity Display data for the user to edit.
ACTION_MAIN activity Start up as the initial activity of a task, with no data input and no returned output.
ACTION_SYNC activity Synchronize data on a server with data on the mobile device.
ACTION_BATTERY_LOW broadcast receiver A warning that the battery is low.
ACTION_HEADSET_PLUG broadcast receiver A headset has been plugged into the device, or unplugged from it.
ACTION_SCREEN_ON broadcast receiver The screen has been turned on.
ACTION_TIMEZONE_CHANGED broadcast receiver The setting for the time zone has changed.
2 Intent的构造函数:
1).Intent() //用到过
Create an empty intent.
2).Intent(Intent o)
Copy constructor.
3).Intent(String action)
Create an intent with a given action.
4).Intent(String action, Uri uri) //用到过
Create an intent with a given action and for a given data url.
5). Intent(Context packageContext, Class<?> cls) //用到过
Create an intent for a specific component.
6). Intent(String action, Uri uri, Context packageContext, Class<?> cls)
Create an intent for a specific component with a specified action and data.
3.static Uri parse(String uriString) 这个函数在android.net.Uri里面,是一个静态方法
Creates a Uri which parses the given encoded URI string.