Android 重新定义一个广播修改系统时间,避免系统时间混乱

有时候,搞不懂为什么手机设备无法准确定义系统时间,出现混乱或显示与实际不符,需要重置或重新设定一次才行,也是真的够无语的!!

vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml

<!--无法从设置外部触发。统计数据可以触发它,因为我们发送

对它犹豫不决-->

<receiver android:name=".fuelgauge.batterytip.AnomalyConfigReceiver "

android:exported="true">

<intent-filter>

<action android:name="android.app.action.STATSD_STARTED"/>

<action android:name="android.intent.action.BOOT_COMPLETED"/>

<action android:name="com.android.set.system_time"/>

</intent-filter>

</receiver>

/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/fuelgauge/batterytip/AnomalyConfigReceiver.java

//*/broadcast modify system time

import android.provider.Settings;

import android.app.AlarmManager;

//*/

public class AnomalyConfigReceiver extends BroadcastReceiver {

private static final String TAG = "AnomalyConfigReceiver";

@Override

public void onReceive(Context context, Intent intent) {

if (StatsManager.ACTION_STATSD_STARTED.equals(intent.getAction())

|| Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {

final StatsManager statsManager = context.getSystemService(StatsManager.class);

// Check whether to update the config

AnomalyConfigJobService.scheduleConfigUpdate(context);

try {

BatteryTipUtils.uploadAnomalyPendingIntent(context, statsManager);

} catch (StatsManager.StatsUnavailableException e) {

Log.w(TAG, "Failed to uploadAnomalyPendingIntent.", e);

}

if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {

AnomalyCleanupJobService.scheduleCleanUp(context);

}

}

//*/add broadcast modify system time

if ("com.android.set.system_time ".equals(intent.getAction())) {

String tzId = intent.getStringExtra("timeZone");
String timeFormat = intent.getStringExtra("timeFormat");
long when = intent.getLongExtra("when",0);

android.util.Log.i("TP","com.tyd.system_time tzId = "+tzId);

android.util.Log.i("TP","com.tyd.system_time timeFormat = "+timeFormat);

android.util.Log.i("TP","com.tyd.system_time when ="+when);

Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE,0);//【置0重新设置一次】
context.getSystemService(AlarmManager.class).setTimeZone(tzId);
android.provider.Settings.System.putString(context.getContentResolver(),
android.provider.Settings.System.TIME_12_24, timeFormat);
context.getSystemService(AlarmManager.class).setTime(when);

}

//*/

}

}

相关推荐
三8441 小时前
PHP Session 反序列化(2):漏洞根因 —— 序列化处理器错位与对象注入
android·web安全·php·反序列化·session
天空之城--2 小时前
Android行业一周动态:编码趋势与行业资讯汇总
android·性能优化·架构·kotlin·android jetpack
Co_Hui4 小时前
Android Handler 内存泄漏分析
android
张小姐的猫4 小时前
【AI大模型接入SDK】 —— Gemini接入封装
android·数据结构·数据库·c++·人工智能·python
Anhty7 小时前
叮咚变声器上手实测,iOS短板、安卓悬浮窗使用感受分享
android·人工智能·功能测试·ios·智能手机
方白羽8 小时前
OkHttp 5.3 隐形变更引发的线上偶发崩溃复盘
android·app·客户端
EatFan9 小时前
【实战经验】uni-app使用 SSE 踩坑,EventSource不支持怎么办?
android·后端·ios·uni-app
JMchen10 小时前
第 2 篇|Kotlin 进阶 —— 集合、循环与条件表达式
android·kotlin
律宏阔10 小时前
Android 自定义 Launcher 加载第三方 App Widget
android
律宏阔10 小时前
Android 9 开发板实现系统侧滑返回
android