How do I edit the text of foreground service notifications?

  • Thread starter Darkmisc
  • Start date
  • Tags
    Edit Text
In summary, the conversation revolved around creating a timer that continues to run on the lock screen after the power button is pressed. The person had attempted to use a foreground notification for this and referenced code from a specific page. However, they encountered an issue with the setContentText and setContentTitle methods not working. Upon further investigation, they realized that the problem was due to not setting an icon with the setSmallIcon method. Once the icon was set, the text and title were able to be changed successfully.
  • #1
Darkmisc
206
28
TL;DR Summary
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:

notification:
  Notification.Builder notification = new Notification.Builder(this, CHANNELID)
                .setContentText("Activity Recognition is running....")
                .setContentTitle("Obesity Point");

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
  • #2
Nevermind. The problem was that I didn't set an icon with .setSmallIcon. The text changes now that I've done that.
 
  • Like
Likes Tom.G

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
891
  • Programming and Computer Science
Replies
0
Views
880
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Computing and Technology
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
314
  • Programming and Computer Science
Replies
6
Views
2K
Back
Top