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);