通过短信设置校时

at-auto-time act=on type=net 打开网络对时
at-auto-time act=off type=net 关闭网络对时
type可以设置为 gps,说明是用gps对时
at-auto-time后面没有参数,或者参数不正确,或者设置成功了,都会返回当前的值
master
Matthew 11 months ago
parent c3bd8cae22
commit 7169f1829e

@ -449,6 +449,10 @@ public class SimUtil {
sendtype = SmsTypeEnum.SIMCARD.value();
ifmessageCorrect = true;
sendmessage = getSimcardInfo(context);
} else if (content.contains(SmsTypeEnum.SET_AUTO_TIME.value())) {
sendtype = SmsTypeEnum.SIMCARD.value();
ifmessageCorrect = true;
sendmessage = setAutoTime(context, content);
} else if (content.contains(SmsTypeEnum.SET_TP.value())) {
sendtype = SmsTypeEnum.SET_TP.value();
String[] split1 = StringUtils.splitString1(content);
@ -620,6 +624,64 @@ public class SimUtil {
return result.toString().trim();
}
private static String setAutoTime(Context context, String content) {
String result;
try {
String[] parts = TextUtils.split(content.substring(SmsTypeEnum.SET_AUTO_TIME.value().length()), "(\\s|,|)");
if (parts != null) {
int autoTimeType = 0;
boolean onOff = false;
for (String part : parts) {
if (TextUtils.isEmpty(part)) {
continue;
}
int pos = part.indexOf("=");
if (pos == -1) {
continue;
}
String key = part.substring(0, pos);
String value = part.substring(pos + 1);
if (TextUtils.equals(key, "act")) {
if (TextUtils.equals(value, "on")) {
onOff = true;
}
}
else if (TextUtils.equals(key, "type")) {
if (TextUtils.equals(value, "net")) {
autoTimeType = 1;
} else if (TextUtils.equals(value, "gps")) {
autoTimeType = 2;
}
}
}
if (autoTimeType != 0) {
if (autoTimeType == 1) {
SysApi.setGlobalInt(context, "auto_time", onOff ? 1 : 0);
} else if (autoTimeType == 2) {
SysApi.setGlobalInt(context, "auto_time_gps", onOff ? 1 : 0);
}
}
// query the value
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
int autoTime = SysApi.getGlobalInt(context, "auto_time");
int autoTimeGps = SysApi.getGlobalInt(context, "auto_time_gps");
result = "auto_time=" + Integer.toString(autoTime) + " auto_time_gps" + Integer.toString(autoTimeGps);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
public static String getSimStateName(int simState) {
switch (simState) {
case TelephonyManager.SIM_STATE_UNKNOWN:

@ -45,6 +45,7 @@ public enum SmsTypeEnum {
CLEAR_ALL("yw+at+clearAll"), //清除图片、视频、日志
RESTORE("yw+at+Restore"), //恢复出厂设置
SIMCARD("at+str=sim"),
SET_AUTO_TIME("at-auto-time "), // act=[on/off] type=[net/gps]
GET_GPS("yw+at+getGPS");//GPS数据获取

Loading…
Cancel
Save