|
|
@ -45,7 +45,7 @@ public class SimUtil {
|
|
|
|
public static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
|
|
|
|
public static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
|
|
|
|
public static final String SMS_DELIVER_ACTION = "android.provider.Telephony.SMS_DELIVER";
|
|
|
|
public static final String SMS_DELIVER_ACTION = "android.provider.Telephony.SMS_DELIVER";
|
|
|
|
|
|
|
|
|
|
|
|
//自定义ACTION常数 作为广播的IntentFilter识别常数
|
|
|
|
// 自定义ACTION常数 作为广播的IntentFilter识别常数
|
|
|
|
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
|
|
|
|
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
|
|
|
|
|
|
|
|
|
|
|
|
public static String SMSTYPE = "smstype";
|
|
|
|
public static String SMSTYPE = "smstype";
|
|
|
@ -53,8 +53,8 @@ public class SimUtil {
|
|
|
|
public static String SMSIFCORRECT = "smsifcorrect";
|
|
|
|
public static String SMSIFCORRECT = "smsifcorrect";
|
|
|
|
|
|
|
|
|
|
|
|
//短信解析
|
|
|
|
//短信解析
|
|
|
|
public static void analysisSMSInfo(Intent intent, Context context) {
|
|
|
|
public static void analysisSMSInfo(final Context context, final Intent intent, final SmsMessage smsMessage) {
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent);
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent, smsMessage);
|
|
|
|
if (smsInfo != null) {
|
|
|
|
if (smsInfo != null) {
|
|
|
|
String packageName = context.getApplicationContext().getPackageName();
|
|
|
|
String packageName = context.getApplicationContext().getPackageName();
|
|
|
|
String content = smsInfo.getContent();
|
|
|
|
String content = smsInfo.getContent();
|
|
|
@ -71,15 +71,15 @@ public class SimUtil {
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendtype = SmsTypeEnum.REBOOT1.value();
|
|
|
|
sendtype = SmsTypeEnum.REBOOT1.value();
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
} else if (content.contains(SmsTypeEnum.REBOOT2.value())) {
|
|
|
|
} else if (content.contains(SmsTypeEnum.REBOOT2.value()) || content.contains(SmsTypeEnum.REBOOT3.value())) {
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendtype = SmsTypeEnum.REBOOT2.value();
|
|
|
|
sendtype = SmsTypeEnum.REBOOT2.value();
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
} else if (content.contains(SmsTypeEnum.RESTART_MP.value())) {
|
|
|
|
} else if (content.contains(SmsTypeEnum.RESTART_MP.value()) || content.contains(SmsTypeEnum.RESTART_MP2.value())) {
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendtype = SmsTypeEnum.RESTART_MP.value();
|
|
|
|
sendtype = SmsTypeEnum.RESTART_MP.value();
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
} else if (content.contains(SmsTypeEnum.RESTART_MPMST.value())) {
|
|
|
|
} else if (content.contains(SmsTypeEnum.RESTART_MPMST.value()) || content.contains(SmsTypeEnum.RESTART_MPMST2.value())) {
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendtype = SmsTypeEnum.RESTART_MPMST.value();
|
|
|
|
sendtype = SmsTypeEnum.RESTART_MPMST.value();
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
|
sendmessage = getSendString(content, ifmessageCorrect);
|
|
|
@ -658,39 +658,27 @@ public class SimUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//短信解析
|
|
|
|
//短信解析
|
|
|
|
public static SmsMessageModel getSMSInfo(Intent intent) {
|
|
|
|
public static SmsMessageModel getSMSInfo(final Intent intent, final SmsMessage smsMessage) {
|
|
|
|
SmsMessageModel smsMessageModel = new SmsMessageModel();
|
|
|
|
SmsMessageModel smsMessageModel = new SmsMessageModel();
|
|
|
|
String action = intent.getAction();
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
if (SMS_RECEIVED_ACTION.equals(action) || SMS_DELIVER_ACTION.equals(action)) {
|
|
|
|
String sender = "";
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
String dateContent = "";
|
|
|
|
if (bundle != null) {
|
|
|
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
content.append(smsMessage.getMessageBody());// 得到短信内容
|
|
|
|
String sender = "";
|
|
|
|
// 得到发信息的号码
|
|
|
|
String dateContent = "";
|
|
|
|
sender = smsMessage.getOriginatingAddress();
|
|
|
|
Object[] pdus = (Object[]) bundle.get("pdus");
|
|
|
|
Date date = new Date(smsMessage.getTimestampMillis());
|
|
|
|
if (pdus != null && pdus.length > 0) {
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
SmsMessage[] messages = new SmsMessage[pdus.length];
|
|
|
|
format.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
|
|
|
|
for (int i = 0; i < pdus.length; i++) {
|
|
|
|
dateContent = format.format(date);
|
|
|
|
byte[] pdu = (byte[]) pdus[i];
|
|
|
|
|
|
|
|
messages[i] = SmsMessage.createFromPdu(pdu);
|
|
|
|
// smsMessage.getIndexOnSim()
|
|
|
|
}
|
|
|
|
int smsSlot = getSmsSlot(intent.getExtras());
|
|
|
|
for (SmsMessage message : messages) {
|
|
|
|
smsMessageModel.setContent(content.toString());
|
|
|
|
content.append(message.getMessageBody());// 得到短信内容
|
|
|
|
smsMessageModel.setSender(sender);
|
|
|
|
// 得到发信息的号码
|
|
|
|
smsMessageModel.setDateContent(dateContent);
|
|
|
|
sender = message.getOriginatingAddress();
|
|
|
|
smsMessageModel.setSlot(smsSlot);
|
|
|
|
Date date = new Date(message.getTimestampMillis());
|
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
format.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
|
|
|
|
|
|
|
|
dateContent = format.format(date);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int smsSlot = getSmsSlot(bundle);
|
|
|
|
|
|
|
|
smsMessageModel.setContent(content.toString());
|
|
|
|
|
|
|
|
smsMessageModel.setSender(sender);
|
|
|
|
|
|
|
|
smsMessageModel.setDateContent(dateContent);
|
|
|
|
|
|
|
|
smsMessageModel.setSlot(smsSlot);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return smsMessageModel;
|
|
|
|
return smsMessageModel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|