Android でフォアグラウンド サービスをセットアップしています。通知テキストを更新したいと思います。以下のようなサービスを作成しています。
このフォアグラウンド サービス内で設定されている通知テキストを更新するにはどうすればよいですか? 通知を更新するためのベスト プラクティスは何ですか? サンプルコードをいただければ幸いです。
public class NotificationService extends Service {
private static final int ONGOING_NOTIFICATION = 1;
private Notification notification;
@Override
public void onCreate() {
super.onCreate();
this.notification = new Notification(R.drawable.statusbar, getText(R.string.app_name), System.currentTimeMillis());
Intent notificationIntent = new Intent(this, AbList.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
this.notification.setLatestEventInfo(this, getText(R.string.app_name), "Update This Text", pendingIntent);
startForeground(ONGOING_NOTIFICATION, this.notification);
}
以下に示すように、メインのアクティビティでサービスを作成しています。
// Start Notification Service
Intent serviceIntent = new Intent(this, NotificationService.class);
startService(serviceIntent);