# ForegroundInfo

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/ForegroundInfo.java+class:androidx.work.ForegroundInfo) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

*** ** * ** ***


```
public final class ForegroundInfo
```

<br />

*** ** * ** ***

The information required when a `https://developer.android.com/reference/androidx/work/ListenableWorker` runs in the context of a foreground service.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/work/ForegroundInfo#ForegroundInfo(int,android.app.Notification)(int notificationId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification)` Creates an instance of `https://developer.android.com/reference/androidx/work/ForegroundInfo` with a `https://developer.android.com/reference/android/app/Notification.html`. |
| `https://developer.android.com/reference/androidx/work/ForegroundInfo#ForegroundInfo(int,android.app.Notification,int)( int notificationId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification, int foregroundServiceType )` Creates an instance of `https://developer.android.com/reference/androidx/work/ForegroundInfo` with a `https://developer.android.com/reference/android/app/Notification.html` and foreground `https://developer.android.com/reference/android/app/Service.html` type. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html o)` |
| `int` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#getForegroundServiceType()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#getNotification()()` |
| `int` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#getNotificationId()()` |
| `int` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#hashCode()()` |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/work/ForegroundInfo#toString()()` |

## Public constructors

### ForegroundInfo

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

```
public ForegroundInfo(int notificationId, @NonNull Notification notification)
```

Creates an instance of `https://developer.android.com/reference/androidx/work/ForegroundInfo` with a `https://developer.android.com/reference/android/app/Notification.html`.

On API 29 and above, you can specify a `foregroundServiceType` by using the `https://developer.android.com/reference/androidx/work/ForegroundInfo#ForegroundInfo(int,android.app.Notification,int)` constructor; otherwise, a default `
foregroundServiceType` of `0` will be used.

| Parameters |
|---|---|
| `int notificationId` | The `https://developer.android.com/reference/android/app/Notification.html` id |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification` | The `https://developer.android.com/reference/android/app/Notification.html` to show when the Worker is running in the context of a foreground `https://developer.android.com/reference/android/app/Service.html` |

### ForegroundInfo

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

```
public ForegroundInfo(
    int notificationId,
    @NonNull Notification notification,
    int foregroundServiceType
)
```

Creates an instance of `https://developer.android.com/reference/androidx/work/ForegroundInfo` with a `https://developer.android.com/reference/android/app/Notification.html` and foreground `https://developer.android.com/reference/android/app/Service.html` type. For more information look at `android.app.Service#startForeground(int,
Notification, int)`.

| Parameters |
|---|---|
| `int notificationId` | The `https://developer.android.com/reference/android/app/Notification.html` id |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification` | The `https://developer.android.com/reference/android/app/Notification.html` |
| `int foregroundServiceType` | The foreground `https://developer.android.com/reference/android/content/pm/ServiceInfo.html` type |

## Public methods

### equals

```
public boolean equals(Object o)
```

### getForegroundServiceType

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

```
public int getForegroundServiceType()
```

| Returns |
|---|---|
| `int` | The foreground `https://developer.android.com/reference/android/content/pm/ServiceInfo.html` type |

### getNotification

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

```
public @NonNull Notification getNotification()
```

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html` | The user visible `https://developer.android.com/reference/android/app/Notification.html` |

### getNotificationId

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/work#2.3.0)

```
public int getNotificationId()
```

| Returns |
|---|---|
| `int` | The `https://developer.android.com/reference/android/app/Notification.html` id to be used |

### hashCode

```
public int hashCode()
```

### toString

```
public String toString()
```