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

SIr*_*lot 5 android

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

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

Nei*_*end 0

我不确定您是否仍在寻找答案,因为您自己已经提供了答案。但是,如果您想实现最初的目标,您可能会想要

  • 每当时间改变时重建 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
        }
    }
};
Run Code Online (Sandbox Code Playgroud)