Android通知时间格式是如何更新的?
我正在为AndroidNotification使用自定义RemoteView,我想模拟系统行为Android通知时间格式是如何更新的?,android,Android,我正在为AndroidNotification使用自定义RemoteView,我想模拟系统行为 Android如何更新其通知时间格式?一旦设置,它们是否会改变?我如何才能模拟这种行为?我对通知时间格式不太了解,但是如果您想模拟他们的行为,应该看看DateUtils类,尤其是我认为与您描述的相同的。添加通知后不可能更新通知,除非使用相同的ID再次调用.notify 如果处理时间戳,最好使用本机Notification NotificationCompat.Builder而不使用RemoteView
Android如何更新其通知时间格式?一旦设置,它们是否会改变?我如何才能模拟这种行为?我对通知时间格式不太了解,但是如果您想模拟他们的行为,应该看看
DateUtils
类,尤其是我认为与您描述的相同的。添加通知后不可能更新通知,除非使用相同的ID再次调用.notify
如果处理时间戳,最好使用本机Notification NotificationCompat.Builder而不使用RemoteView。我不确定您是否仍在寻找答案,因为您自己已经提供了答案。然而,如果你想达到你原来的目标,你可能会想要
- 每当时间发生变化时重新构建RemoteView(这更简单)
- 设置一个广播接收器来捕捉时钟的滴答声,这样你就知道时间什么时候变了
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
}
}
};
每次更新通知时,都要做一些简单的事情(24小时)
public void updateNotifyTime(RemoteViews CustomNotifyView){
日期当前时间=新日期();
int mins=currentTime.getMinutes();
字符串minString=“”;
if(minsI)回答了我的部分问题。但是,这并不能解决我的问题。我有一个带有自定义视图(使用setContent)的RemoteView。我希望在通知中显示日期或时间,模仿本机Android的行为。我将使用API调用(DateUtils.formatSameDayTime)来实现这一点。问题是,一旦在RemoteView上创建了SetTextViewText,并且调用了notificationManager.notify,则该文本是永久性的。我希望日期或时间根据经过的时间动态更改(超过24小时将显示日期)。请帮助。我希望通知根据时间的推移自行更新,就像本地通知一样。有点复杂,但这是一个合法的解决方案。它是-如果有一个不太复杂的方法来做它(和它的工作一致等),我希望看到它。感谢勾号和赏金,感谢它。
public void updateNotifTime(RemoteViews customNotifView){
Date currentTime = new Date();
int mins = currentTime.getMinutes();
String minString = "";
if(mins<10){
minString = "0";
}
minString += mins;
customNotifView.setTextViewText(R.id.time, currentTime.getHours()+":"+minString);
}