微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/android/430814.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐