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