我正在尝试在新的通知中启动计时器,但是从暂停的(经过的)“经过的时间从另一个计时器得到”,而不是从零开始
计时器通知[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(Exam exam)
{
...
}
中的起始base
与RemoteViews.class
中的起始基数不同,它有不同的计算
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
从零开始
答案 0 :(得分:0)
我尝试了很多计算方法,最终得到了这个。
notification.contentView.setChronometer(R.id.chronometer_recorder
, (SystemClock.elapsedRealtime() + timeWhenPaused)
, null
, true
);
然后
long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();
答案 1 :(得分:0)
我希望这会有所帮助>>>> 我使用远程视图的计时器示例(在通知中)。
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);