写应用经常会遇到获取通讯联系人列表,发送短信,
附上demo下载地址:http://download.youkuaiyun.com/detail/hap_gx/5308860
首先介绍一下发送短信的两种方式:
一、静默发送。也就是在用户不知道的情况下,直接把短信发送出去,很是流氓。个人不推荐,而且谷歌查出这样的问题,很有可能把你的应用下架。
二、系统发送。直接调用系统自动发送短信功能,不需要在清单文件中添加很短权限。一般都是使用这种方式。
第一:调用系统短信接口直接发送短信;主要代码如下:
//直接调用短信接口发短信
SmsManager smsManager = SmsManager.getDefault();
List<String> divideContents = smsManager.divideMessage(content);
for (String text : divideContents) {
smsManager.sendTextMessage("150xxxxxxxx", null, text, sentPI, deliverPI);
}
第二:调起系统发短信功能;主要代码如下:
Uri uri = Uri.parse("smsto:10086");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_bod