0

アプリにフォアグラウンド サービスがあり、通知に動的に更新されたテキストが含まれています。

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

しかし、アクティビティからも更新できるようにしたいのですが、サービスを再起動せずにどうすればそれを行うことができますか?

4

1 に答える 1

1

このアプローチを使用できます

final Notification notification = buildForegroundNotification();
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(Constants.FOREGROUND_ID, notification);
于 2014-10-08T15:08:19.960 に答える