【问题标题】:Chronometer start from specific value in Notification RemoteViews计时器从 Notification RemoteViews 中的特定值开始
【发布时间】:2018-06-04 05:18:37
【问题描述】:

我正在尝试在新通知中启动计时器,但从暂停(经过)“经过的时间来自另一个计时器”,而不是从零开始

时计的NotificationRemoteViews.class中的起始baseChronometer.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
                    );

从零开始

【问题讨论】:

    标签: android android-notifications chronometer android-remoteview


    【解决方案1】:

    我尝试了很多计算方法终于得到了这个。

    long elapsedMillis = SystemClock.elapsedRealtime() - myChronometer.getBase();
    

    然后

    notification.contentView.setChronometer(R.id.chronometer_recorder_notification
                        ,(SystemClock.elapsedRealtime() - elapsedMillis ^5)
                        ,null
                        ,true
                );
    

    【讨论】:

      【解决方案2】:

      希望对你有帮助>>>> 我使用远程视图的计时器的工作示例(在通知中)。

      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

      【讨论】:

        猜你喜欢
        • 2014-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-22
        相关资源
        最近更新 更多