Android通知时间格式如何更新?

我正在使用自定义RemoteView for AndroidNotification,我想模仿系统行为.

Android如何更新其通知时间格式 – 设置后是否会更改?我怎么能模仿这种行为?

最佳答案
鉴于您自己提供了答案,我不确定您是否还在寻找答案.但是,如果您希望实现原始目标,则可能需要

>每当时间发生变化时重建RemoteView(它更容易)
>设置broadcastReceiver以捕获时钟的滴答,以便您知道时间何时发生变化.

所以,有些代码有点像这样:

class MyCLeverThing extends Service (say) {

    // Your stuff here

    private static IntentFilter timeChangeIntentFilter;
    static {
        timeChangeIntentFilter = new IntentFilter();
        timeChangeIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        timeChangeIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
    }

    // Somewhere in onCreate or equivalent to set up the receiver
    registerReceiver(timeChangedReceiver,timeChangeIntentFilter);

    // The actual receiver
    private final broadcastReceiver timeChangedReceiver = new broadcastReceiver() {
    @Override
    public void onReceive(Context context,Intent intent) {
        final String action = intent.getAction();

        if (action.equals(Intent.ACTION_TIME_CHANGED) ||
            action.equals(Intent.ACTION_TIMEZONE_CHANGED))
        {
            updateWidgets();  // Your code to rebuild the remoteViews or whatever
        }
    }
};

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...