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

}

//*/

}

}

相关推荐
火柴就是我14 分钟前
学习一些常用的混合模式之BlendMode. dst
android·flutter
遥不可及zzz19 分钟前
解决 Google Play 提示的 16KB 内存页面大小对齐问题:通过升级 Android Gradle 插件(AGP)
android
SmartRadio1 小时前
在MT8791 5G硬件平台上舍弃安卓系统-运行OpenWRT系统
android·5g·mt8791
虫小宝1 小时前
导购APP高可用数据库设计:主从分离与分库分表在返利系统中的应用
android·数据库
我命由我123452 小时前
Android Jetpack Compose - TopAppBar、BottomAppBar、Scaffold
android·java·java-ee·kotlin·android studio·android jetpack·android-studio
REDcker2 小时前
Android WebView 升级 - WebViewUpgrade 库使用详解
android·华为·harmonyos·webview
我命由我123452 小时前
Android Studio - Android Studio 去除 import 的未使用的类
android·java·ide·学习·java-ee·android studio·学习方法
ii_best2 小时前
安卓/ios脚本开发辅助工具按键精灵横纵坐标转换教程
android·开发语言·ios·安卓
BD_Marathon2 小时前
SpringMVC——5种类型参数传递
android·java·数据库
a3158238063 小时前
Android 大图显示策略优化显示(二)
android·java·开发语言·javascript·kotlin·glide·图片加载