android - 将字符串值转换为字符序列并在android中的通知中显示

标签 android string notifications charsequence

我想在通知中显示这个函数的结果。

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) {}

最重要的是,您应该将 timestringCountingDownTimer 发送到 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/

相关文章:

android - 如何在android中获取通知计数?

android - 通知多行

Android DBFlow 不生成数据库

java - 如何在android中创建动画饼图?

string - Lua中阿拉伯字母的长度

python - Python 的 Emacs 填充模式不会破坏引起错误的引号字符串

php - 在 HEREDOC 字符串中调用 PHP 函数

Android通知使手机滞后

java - Android Java AppCompatTextView 无法转换为 LinearLayout

java - 在 Android 中实现一个简单的循环