public final class

ForegroundInfo

extends java.lang.Object

 java.lang.Object

↳androidx.work.ForegroundInfo

Gradle dependencies

compile group: 'androidx.work', name: 'work-runtime', version: '2.8.0-alpha02'

  • groupId: androidx.work
  • artifactId: work-runtime
  • version: 2.8.0-alpha02

Artifact androidx.work:work-runtime:2.8.0-alpha02 it located at Google repository (https://maven.google.com/)

Overview

The information required when a ListenableWorker runs in the context of a foreground service.

Summary

Constructors
publicForegroundInfo(int notificationId, Notification notification)

Creates an instance of ForegroundInfo with a Notification.

publicForegroundInfo(int notificationId, Notification notification, int foregroundServiceType)

Creates an instance of ForegroundInfo with a Notification and foreground type.

Methods
public booleanequals(java.lang.Object o)

public intgetForegroundServiceType()

public NotificationgetNotification()

public intgetNotificationId()

public inthashCode()

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public ForegroundInfo(int notificationId, Notification notification)

Creates an instance of ForegroundInfo with a Notification.

On API 29 and above, you can specify a foregroundServiceType by using the ForegroundInfo.ForegroundInfo(int, Notification, int) constructor; otherwise, a default foregroundServiceType of 0 will be used.

Parameters:

notificationId: The Notification id
notification: The Notification to show when the Worker is running in the context of a foreground

public ForegroundInfo(int notificationId, Notification notification, int foregroundServiceType)

Creates an instance of ForegroundInfo with a Notification and foreground type. For more information look at android.app.Service#startForeground(int, Notification, int).

Parameters:

notificationId: The Notification id
notification: The Notification
foregroundServiceType: The foreground type

Methods

public int getNotificationId()

Returns:

The Notification id to be used

public int getForegroundServiceType()

Returns:

The foreground type

public Notification getNotification()

Returns:

The user visible Notification

public boolean equals(java.lang.Object o)

public int hashCode()

public java.lang.String toString()

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.work;

import android.app.Notification;

import androidx.annotation.NonNull;

/**
 * The information required when a {@link ListenableWorker} runs in the context of a foreground
 * service.
 */
public final class ForegroundInfo {

    private final int mNotificationId;
    private final int mForegroundServiceType;
    private final Notification mNotification;

    /**
     * Creates an instance of {@link ForegroundInfo} with a {@link Notification}.
     * <p>
     * On API 29 and above, you can specify a {@code foregroundServiceType} by using the
     * {@link #ForegroundInfo(int, Notification, int)} constructor; otherwise, a default {@code
     * foregroundServiceType} of {@code 0} will be used.
     *
     * @param notificationId The {@link Notification} id
     * @param notification   The {@link Notification} to show when the Worker is running in the
     *                       context of a foreground {@link android.app.Service}
     */
    public ForegroundInfo(int notificationId, @NonNull Notification notification) {
        this(notificationId, notification, 0);
    }

    /**
     * Creates an instance of {@link ForegroundInfo} with a {@link Notification} and foreground
     * {@link android.app.Service} type.
     *
     * For more information look at {@code android.app.Service#startForeground(int,
     * Notification, int)}.
     *
     * @param notificationId        The {@link Notification} id
     * @param notification          The {@link Notification}
     * @param foregroundServiceType The foreground {@link android.content.pm.ServiceInfo} type
     */
    public ForegroundInfo(
            int notificationId,
            @NonNull Notification notification,
            int foregroundServiceType) {
        mNotificationId = notificationId;
        mNotification = notification;
        mForegroundServiceType = foregroundServiceType;
    }

    /**
     * @return The {@link Notification} id to be used
     */
    public int getNotificationId() {
        return mNotificationId;
    }

    /**
     * @return The foreground {@link android.content.pm.ServiceInfo} type
     */
    public int getForegroundServiceType() {
        return mForegroundServiceType;
    }

    /**
     * @return The user visible {@link Notification}
     */
    @NonNull
    public Notification getNotification() {
        return mNotification;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ForegroundInfo that = (ForegroundInfo) o;

        if (mNotificationId != that.mNotificationId) return false;
        if (mForegroundServiceType != that.mForegroundServiceType) return false;
        return mNotification.equals(that.mNotification);
    }

    @Override
    public int hashCode() {
        int result = mNotificationId;
        result = 31 * result + mForegroundServiceType;
        result = 31 * result + mNotification.hashCode();
        return result;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ForegroundInfo{");
        sb.append("mNotificationId=").append(mNotificationId);
        sb.append(", mForegroundServiceType=").append(mForegroundServiceType);
        sb.append(", mNotification=").append(mNotification);
        sb.append('}');
        return sb.toString();
    }
}