android 拨打电话与发送短信
2012-01-18 16:06
447 查看
通过调用android系统提供的电话与短信功能,可以简单的实现发送短信,拨打电话,但是必须在AndroidManifest.xml里面配置相应权限,定位到
标签外面一层,拨打电话的权限为android.permission.CALL_PHONE,发送短信的权限为android.permission.SEND_SMS.
而内部代码主要是写按钮的单击事件就可以了,覆写 onClick()事件
发送短信:
拨打电话:
基于短信发送一个数据到一个特定的应用程序端口(Send a data based SMS to a specific application port.)
基于短信发送多个文本。事先已将短信内容分割为多个部分(Send a multi-part text based SMS. The callee should have already divided the message into correctly sized parts by calling
具体怎么用的还没研究。
<application /application>
标签外面一层,拨打电话的权限为android.permission.CALL_PHONE,发送短信的权限为android.permission.SEND_SMS.
而内部代码主要是写按钮的单击事件就可以了,覆写 onClick()事件
发送短信:
@Override public void onClick(View v) { // 管理短信的操作类,例如发送数据,文本,通过调用getDefault()方法获得对象; SmsManager smsManager = SmsManager.getDefault(); // 如果短信内容多长,将自动分割为多条信息,存放在ArrayList里面; ArrayList<String> textsArrayList = smsManager.divideMessage(conEditText.getText() .toString()); // 利用for循环将短信发送出去; for (String text : textsArrayList) { // 实现发送文本短信的函数是smsManager的sendTextMessage()方法 smsManager.sendTextMessage(phoneEditText.getText().toString(), null, text, null, null); } // 这句话适用于提示用户短信已发送成功的 16 // Toast.makeText(MySMSActivity.this, R.string.success, // Toast.LENGTH_LONG).show(); }
拨打电话:
@Override public void onClick(View v) { String phonenum = phoneEditText.getText().toString(); // 使用Intent Intent intent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + phonenum)); // 开启广播意图 startActivity(intent); }
打电话和发短信都是调用Android系统服务,但是在实现的代码上是不同。在调用smsManager.divideMessage()时发现发送短信的函数还有两个,查看帮助文档知道分别是sendDataMessage 和sendMultipartTextMessage,他们的声明和作用如下:
public void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
基于短信发送一个数据到一个特定的应用程序端口(Send a data based SMS to a specific application port.)
public void sendMultipartTextMessage (String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)
基于短信发送多个文本。事先已将短信内容分割为多个部分(Send a multi-part text based SMS. The callee should have already divided the message into correctly sized parts by calling
divideMessage.)
具体怎么用的还没研究。
相关文章推荐
- Android拨打电话和发送短信
- Android拨打电话和发送短信操作
- android 添加菜单 开发流程 短信发送与拨打电话
- Android中实现拨打电话和发送短信
- Android 之 ACTION_CALL 拨打电话 与 发送短信
- 至Android虚拟机发送短信和拨打电话
- android中拨打电话和短信发送的实现
- android中的拨打电话和发送短信
- 向Android虚拟机发送短信和拨打电话
- android拨打电话和发送短信核心代码
- Android中实现拨打电话、发送短信、响铃、震动和获取当前时间
- Android实现拨打电话、发送短信和发送邮件功能
- Android 打开URL中的网页和拨打电话、发送短信功能
- 脚本控制向Android模拟拨打电话,发送短信,定位设置功能
- android之拨打电话、发送短信
- Android 拨打电话和发送短信
- android发送短信填入手机号码,6.0动态请求权限拨打电话
- Android开发入门之电话拨打与发送短信
- 脚本控制向Android模拟拨打电话,发送短信,定位设置功能
- Android手机拨打电话、手动发送短信与自动拨打电话、自动发送短信(代码很简单哦)