我想在通知中显示这个函数的结果。
public class TimerService extends Service {
public String timeString;
... // service methodd
public class CountingDownTimer extends CountDownTimer{
public CountingDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long leftTimeInMilliseconds) {
timeString = String.format("%02d", 5000/ 60)
+ ":" + String.format("%02d", 5000% 60);
...
}
...// at the end of TimerService class
notification = new NotificationCompat.Builder(this)
.setContentText(timeString).build();
但不幸的是,通知中没有显示任何内容(null)。我能做些什么?如何将 String 值转换为 char 序列?
最佳答案
我之前遇到过类似的问题。您应该创建新方法并将通知放入其中。
private void setupNotification(String s) {}
最重要的是,您应该将 timestring
从 CountingDownTimer
发送到 setupNotification
。所以这样做:
public class CountingDownTimer extends CountDownTimer{
public String timeString=null;
public CountingDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long leftTimeInMilliseconds) {
timeString = String.format("%02d", 5000/ 60)
+ ":" + String.format("%02d", 5000% 60);
setupNotification(timeString);
}
private void setupNotification(String s) {
notification = new NotificationCompat.Builder(this)
.setContentText(s)
}
希望能成功!
关于android - 将字符串值转换为字符序列并在android中的通知中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41142757/