我正在使用自定义RemoteView for AndroidNotification,我想模仿系统行为.
Android如何更新其通知时间格式 - 设置后是否会更改?我怎么能模仿这种行为?
我不确定您是否仍在寻找答案,因为您自己已经提供了答案。但是,如果您想实现最初的目标,您可能会想要
所以,一些代码有点像这样:
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)
| 归档时间: |
|
| 查看次数: |
1351 次 |
| 最近记录: |