How do I edit the text of foreground service notifications?

  • Thread starter Thread starter Darkmisc
  • Start date Start date
  • Tags Tags
    Edit Text
Click For Summary
A user sought assistance in creating a timer that remains active on the lock screen after pressing the power button, considering the use of a foreground notification. They initially encountered issues with modifying the notification's title and text, which remained static despite code changes. The problem was resolved when they realized that not setting an icon with .setSmallIcon was the cause of the issue, leading to successful updates of the notification's text and title.
Darkmisc
Messages
222
Reaction score
31
TL;DR
I'd like to run a timer in a foreground notification. I thought I could use the setContextText command for this, but it doesn't change the text in the notification at all.
Hi everyone

I'd like to make a timer that continues to run on the lock screen after the power button is pressed. I thought I could use a foreground notification for this and used code from this page:

In particular, I thought I could modify the following lines of code:

[CODE lang="java" title="notification"] Notification.Builder notification = new Notification.Builder(this, CHANNELID)
.setContentText("Activity Recognition is running....")
.setContentTitle("Obesity Point");[/CODE]

However, it seems setContentText and setContentTitle do nothing. No matter what I put in the quotation marks, my notification title is " Timer is running" and the text is "Tap for more information or to stop the app".

How do I change the text and title?

Thanks
 
Technology news on Phys.org
Nevermind. The problem was that I didn't set an icon with .setSmallIcon. The text changes now that I've done that.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
10
Views
2K
Replies
1
Views
5K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
4
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
7
Views
920
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
65
Views
7K