0

我在我的应用程序,其中有在通知一个动态更新的文字有前景的服务,我可以更新它只是罚款从更新前台服务notificaton从活动

startForeground(Constants.FOREGROUND_ID, buildForegroundNotification()); 
} 

private Notification buildForegroundNotification() { 
    NotificationCompat.Builder b = new NotificationCompat.Builder(this); 
    b.setOngoing(true); 
    b.setContentIntent(getPendingIntent(this)); 
    b.setContentTitle(getString(R.string.app_name)); 
    b.setContentText(getString(R.string.time) + " " + number); 
    b.setSmallIcon(R.drawable.ic_launcher); 
    return b.build(); 
} 

withing的服务,但我想也能够从活动更新它,我怎么能做到这一点,而无需重新启动服务?

回答

1

您可以使用此方法

final Notification notification = buildForegroundNotification(); 
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(Constants.FOREGROUND_ID, notification);