# ForegroundInfo

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/work/ForegroundInfo "View this page in Java")

<br />

```
class ForegroundInfo
```

<br />

*** ** * ** ***

The information required when a[ListenableWorker](https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker)runs in the context of a foreground service.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                     ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ForegroundInfo](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#ForegroundInfo(int,android.app.Notification))`(notificationId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html)`)` Creates an instance of[ForegroundInfo](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo)with a[Notification](https://developer.android.com/reference/android/app/Notification.html).                                                                                                                                                                                                                               |
| [ForegroundInfo](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#ForegroundInfo(int,android.app.Notification,int))`(` ` notificationId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html)`,` ` foregroundServiceType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Creates an instance of[ForegroundInfo](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo)with a[Notification](https://developer.android.com/reference/android/app/Notification.html)and foreground[android.app.Service](https://developer.android.com/reference/android/app/Service.html)type. |

|                                 ### Public functions                                  |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)   | [equals](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#equals(java.lang.Object))`(o: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!)` |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)           | [getForegroundServiceType](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#getForegroundServiceType())`()`                                                              |
| [Notification](https://developer.android.com/reference/android/app/Notification.html) | [getNotification](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#getNotification())`()`                                                                                |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)           | [getNotificationId](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#getNotificationId())`()`                                                                            |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)           | [hashCode](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#hashCode())`()`                                                                                              |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`  | [toString](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo#toString())`()`                                                                                              |

## Public constructors

### ForegroundInfo

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

```
ForegroundInfo(notificationId: Int, notification: Notification)
```

Creates an instance of[ForegroundInfo](https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo)with a[Notification](https://developer.android.com/reference/android/app/Notification.html).

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

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `notificationId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | The[Notification](https://developer.android.com/reference/android/app/Notification.html)id                                                                                                                                                       |
| `notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html) | The[Notification](https://developer.android.com/reference/android/app/Notification.html)to show when the Worker is running in the context of a foreground[android.app.Service](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)  

```
ForegroundInfo(
    notificationId: Int,
    notification: Notification,
    foregroundServiceType: Int
)
```

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

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| `notificationId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | The[Notification](https://developer.android.com/reference/android/app/Notification.html)id                                      |
| `notification: `[Notification](https://developer.android.com/reference/android/app/Notification.html) | The[Notification](https://developer.android.com/reference/android/app/Notification.html)                                        |
| `foregroundServiceType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)  | The foreground[android.content.pm.ServiceInfo](https://developer.android.com/reference/android/content/pm/ServiceInfo.html)type |

## Public functions

### equals

```
fun equals(o: Any!): Boolean
```  

### getForegroundServiceType

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

```
fun getForegroundServiceType(): Int
```  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The foreground[android.content.pm.ServiceInfo](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)  

```
fun getNotification(): Notification
```  

|                                        Returns                                        |
|---------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| [Notification](https://developer.android.com/reference/android/app/Notification.html) | The user visible[Notification](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)  

```
fun getNotificationId(): Int
```  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The[Notification](https://developer.android.com/reference/android/app/Notification.html)id to be used |

### hashCode

```
fun hashCode(): Int
```  

### toString

```
fun toString(): String!
```