|
@@ -6,11 +6,15 @@ import android.app.PendingIntent;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.media.AudioManager;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.wdkl.ncs.android.component.home.activity.HomeActivity;
|
|
|
import com.wdkl.ncs.android.lib.base.BaseApplication;
|
|
|
|
|
|
+import java.io.DataOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
public class AppUtils {
|
|
|
|
|
|
public static void restartApp() {
|
|
@@ -31,6 +35,67 @@ public class AppUtils {
|
|
|
System.exit(0);
|
|
|
}
|
|
|
|
|
|
+ public static void setSystemTime(Context context, long timeMills, String timeZone) {
|
|
|
+ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
+ //alarmManager.setTimeZone("Asia/Shanghai");
|
|
|
+ alarmManager.setTimeZone(timeZone);
|
|
|
+ alarmManager.setTime(timeMills);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置系统时间
|
|
|
+ *
|
|
|
+ * @param time
|
|
|
+ */
|
|
|
+ public static void setSysTime(String time, String timeZone) {
|
|
|
+ try {
|
|
|
+ Process process = Runtime.getRuntime().exec("su");
|
|
|
+ if (null == process) return;
|
|
|
+ DataOutputStream os = new DataOutputStream(process.getOutputStream());
|
|
|
+ //os.writeBytes("setprop persist.sys.timezone Asia/Shanghai\n");
|
|
|
+ os.writeBytes("setprop persist.sys.timezone " + timeZone + "\n");
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= 24) {//7.1以上的系统
|
|
|
+ String datetime = changeTimeForm(time); //20211213:092314 ------ 051315372019.00
|
|
|
+ os.writeBytes("/system/bin/date " + datetime + " set\n");
|
|
|
+ } else {
|
|
|
+ os.writeBytes("/system/bin/date -s " + time + "\n");//【时间格式 yyyyMMdd.HHmmss】"20131023.112800"
|
|
|
+ }
|
|
|
+ os.writeBytes("clock -w\n");
|
|
|
+ os.writeBytes("exit\n");
|
|
|
+ os.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String changeTimeForm(String t) {
|
|
|
+ if (!TextUtils.isEmpty(t) && t.length() >= 15) {
|
|
|
+ String yyyy = substringByLengh(t, 0, 4);
|
|
|
+ String MMdd = substringByLengh(t, 4, 8);
|
|
|
+ String HHmm = substringByLengh(t, 9, 13);
|
|
|
+ String ss = substringByLengh(t, 13, 15);
|
|
|
+
|
|
|
+ return MMdd + HHmm + yyyy + "." + ss;
|
|
|
+ } else {
|
|
|
+ return "051315372019.00";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String substringByLengh(String str, int start, int end) {
|
|
|
+ if (str == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (start > end) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (str.length() - 1 < start || str.length() < end) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ return str.substring(start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static void switchAudioMode(Context context, boolean speakerOn) {
|
|
|
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
|
audioManager.setSpeakerphoneOn(speakerOn);
|