Updating an ongoing notification quietly

后端 未结 4 1455
感动是毒
感动是毒 2020-11-29 01:55

I have a service which connects to other devices wirelessly. When the service is enabled, I have an ongoing notification which states it is enabled.

After the servi

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 02:39

    This worked for me, whereby an ongoing activity (not SERVICE) notification is updated 'silently'.

    NotificationManager notifManager; // notifManager IS GLOBAL
    note = new NotificationCompat.Builder(this)
        .setContentTitle(YOUR_TITLE)
        .setSmallIcon(R.drawable.yourImageHere);
    
    note.setOnlyAlertOnce(true);
    note.setOngoing(true);
    note.setWhen( System.currentTimeMillis() );
    
    note.setContentText(YOUR_MESSAGE);
    
    Notification notification = note.build();
    notifManager.notify(THE_ID_TO_UPDATE, notification );
    

提交回复
热议问题