计时器从 Notification RemoteViews 中的特定值开始
Chronometer start from specific value in Notification RemoteViews
我正在尝试在新通知中启动计时器,但从暂停(已过)"the elapsed time is got from another chronometer",而不是从零开始
计时器通知 RemoteViews.class
中的开始 base
与 Chronometer.class
中的开始基地不同,它有不同的计算
Notification notification = new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(songName).build();
notification.contentView = simpleContentView;
然后我得到 timeWhenPaused
long timeWhenPaused = myChronometer.getBase() - SystemClock.elapsedRealtime();
然后创建 chronometer
notification.contentView.setChronometer(R.id.chronometer_recorder
, (SystemClock.elapsedRealtime() + timeWhenPaused)
, null
, true
);
从零开始
我试了很多方法计算终于搞定了
long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();
然后
notification.contentView.setChronometer(R.id.chronometer_recorder_notification
,(SystemClock.elapsedRealtime() - elapsedMillis ^5)
,null
,true
);
希望对您有所帮助>>>
我使用远程视图的计时器的工作示例(在通知中)。
long startTime = SystemClock.elapsedRealtime();
Calendar endTime = Calendar.getInstance(); // time in future
endTime.set(Calendar.HOUR_OF_DAY, YOUR_HOUR);
endTime.set(Calendar.MINUTE, YOUR_MINUTE);
endTime.set(Calendar.SECOND, 0);
Date now = new Date();
long elapsed = now.getTime() - endTime.getTimeInMillis();
long remainingTime = startTime - elapsed;
remoteViews.setChronometerCountDown(R.id.chronometer, true);
remoteViews.setChronometer(R.id.chronometer, remainingTime, ("%tH:%tM:%tS"), true);
picture of my notification
我正在尝试在新通知中启动计时器,但从暂停(已过)"the elapsed time is got from another chronometer",而不是从零开始
计时器通知 RemoteViews.class
中的开始 base
与 Chronometer.class
中的开始基地不同,它有不同的计算
Notification notification = new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(songName).build();
notification.contentView = simpleContentView;
然后我得到 timeWhenPaused
long timeWhenPaused = myChronometer.getBase() - SystemClock.elapsedRealtime();
然后创建 chronometer
notification.contentView.setChronometer(R.id.chronometer_recorder
, (SystemClock.elapsedRealtime() + timeWhenPaused)
, null
, true
);
从零开始
我试了很多方法计算终于搞定了
long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();
然后
notification.contentView.setChronometer(R.id.chronometer_recorder_notification
,(SystemClock.elapsedRealtime() - elapsedMillis ^5)
,null
,true
);
希望对您有所帮助>>> 我使用远程视图的计时器的工作示例(在通知中)。
long startTime = SystemClock.elapsedRealtime();
Calendar endTime = Calendar.getInstance(); // time in future
endTime.set(Calendar.HOUR_OF_DAY, YOUR_HOUR);
endTime.set(Calendar.MINUTE, YOUR_MINUTE);
endTime.set(Calendar.SECOND, 0);
Date now = new Date();
long elapsed = now.getTime() - endTime.getTimeInMillis();
long remainingTime = startTime - elapsed;
remoteViews.setChronometerCountDown(R.id.chronometer, true);
remoteViews.setChronometer(R.id.chronometer, remainingTime, ("%tH:%tM:%tS"), true);
picture of my notification