实验要求
1)点击”打电话”: 进入拨号界面
2). 长按”打电话”: 直接拨打电话
3). 点击”发短信”: 进入编辑短信界面
4). 长按”发短信”: 直接将短信发送出去
实验技术点
1). 布局的设计
2). 点击事件和长按事件监听的添加
3). 使用隐式意图拨打电话,进入拨号界面, 进入发短信界面: 4). 使用SmsMessager发送短信
5). 权限的声明(如打电话, 发短信)
打电话和发短信的权限
进入电话拨打界面的意图: Intent.ACTION_DIAL
进入短信编辑界面的意图: Intent.ACTION_SENDTO
拨打电话的意图: Intent.ACTION_CALL
发送短信的工具类: SmsManager
需要的权限:
打电话的权限: android.permission.CALL_PHONE
发短信的权限: android.permission.SEND_SMS
拨打电话的Uri: tel:110
进入短信界面的电话Uri : smsto:110
携带额外短信数据的标识名为: sms_body
activity_main.xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电话号码: " />
<EditText
android:id="@+id/et_main_number"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
and