Как обновить текст Foreground Service - PullRequest
0 голосов
/ 10 ноября 2019

Мой класс обслуживания:

public class ExampleService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String input = intent.getStringExtra("inputExtra");
        boolean update = intent.getBooleanExtra("update",false);

        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,
                0, notificationIntent, 0);

        Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentTitle("Состояние сервера:")
                .setContentText(input)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .build();

        startForeground(1, notification);

        //do heavy work on a background thread
        //stopSelf();
        return START_STICKY;
    }
}

Мой стартовый сервис:

Intent serviceIntent = new Intent(MainActivity.this, ExampleService.class);
                    serviceIntent.putExtra("inputExtra", status);
                    ContextCompat.startForegroundService(MainActivity.this, serviceIntent);

Я получаю данные с сервера (статус мой сервер Online / Offline) от okhttp3 Как я могу обновить текст намое уведомление? По запросу из моего MainActivity.class?

...