How do I edit the text of foreground service notifications?

  • Thread starter Thread starter Darkmisc
  • Start date Start date
  • Tags Tags
    Edit Text
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 2K views
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
 
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.
 
Reply
  • Like
Likes   Reactions: Tom.G