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);

}

//*/

}

}

相关推荐
yi诺千金24 分钟前
Android U 自由窗口(浮窗)——启动流程(system_server侧流程)
android
清空mega3 小时前
第11章 网络编程
android·网络
自动化BUG制造器3 小时前
Android UI 线程不一定是主线程
android
无知的前端3 小时前
一文读懂-Jetpack与AndroidX
android·kotlin·android jetpack
河铃旅鹿5 小时前
Android开发-java版:SQLite数据库
android·数据库·笔记·学习·sqlite
旋律逍遥5 小时前
《Framework 开发》3、开发工具及命令行知识装备
android
啦啦9117145 小时前
安卓手机/平板/TV版 Rotation强制横屏显示工具!免ROOT可用!再推荐突破手机限制的3款神器
android·智能手机·电脑
汤面不加鱼丸6 小时前
flutter实践:混合app在部分android旧机型上显示异常
android·flutter
_李小白7 小时前
【Android FrameWork】延伸阅读:ActivityManagerService启动Activity
android
用户41659673693557 小时前
Android 媒体库高效扫描器:基于协程与 `ContentObserver` 的 `FileScanner`
android