?做了一个简单的批量发短信小工具。功能:从?sdcard?中读取发送短信的手机列表,每行一个手机号(存在/sdcard/ADAGroupSMS/PhoneNum.txt),批量发送短信。适用于广告推广、短信任务。
?主要步骤如下:
1. 如何发送单条短信
?
- //如果内容大于70字,则拆分为多条??
- List<String>?textMsgs=sms.divideMessage(strmessage);??
- try??
- {??
- ????for(String?textMsg:textMsgs)?//长信息逐条发送??
- ????{??
- ????????PendingIntent?pendIntent?=?PendingIntent.getBroadcast(ADAGroupSMS.this,?0,?new?Intent(),?0);??
- ????????sms.sendTextMessage(SentNum,?null,?textMsg,?pendIntent,?null);???
- ????}??
- }??
- catch(Exception?e)???
- {???
- ????e.printStackTrace();???
- }??
?
?
2. 如何在模拟器上模拟收发短信
建立两个avd,一个avd运行一个实例就行
3. 如何在模拟器上创建?sdcard image?,如何存放文件
Android - 图解如何模拟sd card,管理sd card
4. 如何读取?sdcard?文件
?
- try??
- {??
- ????reader=new?BufferedReader(new?FileReader(filename));??
- ????//当readLine方法返回null时表示文件读取完毕。??
- ????while((SentNum=reader.readLine())!=null)??
- ????{??
- ??//?.................??
- ????}??
- }??
- catch(IOException?e)??
- {??
- ????e.printStackTrace();??
- }??
- finally??
- {??
- ????//最后要在finally中将reader对象关闭??
- ????if(reader!=null)??
- ????{??
- ????????try{??
- ????????????reader.close();??
- ????????}catch(IOException?e){??
- ????????????e.printStackTrace();??
- ????????}??
- ????}??
- }??
?
5. 如何判断是否手机号
?
?
- private?boolean?isPhoneNumber(String?mobilenum)?{??
- ????//?TODO?Auto-generated?method?stub??
- ????String?expression0??="^//(?(//d{11})//)$";?//xxxxxxxxxxx??
- ????String?expression1?="^//(?(//d{3})//)?[-?]?(//d{3})[-?]?(//d{5})$";?//xxx-xxx-xxxxx??
- ????String?expression2?="^//(?(//d{3})//)?[-?]?(//d{4})[-?]?(//d{4})$";?//xxx-xxxx-xxxx???????
- ????Pattern?p0=Pattern.compile(expression0);??
- ????Matcher?m0=p0.matcher(mobilenum);??
- ????Pattern?p1=Pattern.compile(expression1);??
- ????Matcher?m1=p1.matcher(mobilenum);??
- ????Pattern?p2=Pattern.compile(expression2);??
- ????Matcher?m2=p2.matcher(mobilenum);??
- ????if(m0.matches()||m1.matches()||m2.matches())??
- ????{??
- ????????return?true;??
- ????}??
- ????????return?false;??
- }???