Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Inherited Constants](https://developer.android.com/reference/android/service/notification/StatusBarNotification#inhconstants) \| [Fields](https://developer.android.com/reference/android/service/notification/StatusBarNotification#lfields) \| [Ctors](https://developer.android.com/reference/android/service/notification/StatusBarNotification#pubctors) \| [Methods](https://developer.android.com/reference/android/service/notification/StatusBarNotification#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/service/notification/StatusBarNotification#inhmethods)

# StatusBarNotification

*** ** * ** ***

` public class StatusBarNotification `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.notification.StatusBarNotification |

<br />

*** ** * ** ***

Class encapsulating a Notification. Sent by the NotificationManagerService to clients including the status bar and any `https://developer.android.com/reference/android/service/notification/NotificationListenerService`s.

## Summary

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/service/notification/StatusBarNotification>` | `https://developer.android.com/reference/android/service/notification/StatusBarNotification#CREATOR` <br /> |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#StatusBarNotification(android.os.Parcel)(https://developer.android.com/reference/android/os/Parcel in) ` |
| ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#StatusBarNotification(java.lang.String,%20java.lang.String,%20int,%20java.lang.String,%20int,%20int,%20int,%20android.app.Notification,%20android.os.UserHandle,%20long)(https://developer.android.com/reference/java/lang/String pkg, https://developer.android.com/reference/java/lang/String opPkg, int id, https://developer.android.com/reference/java/lang/String tag, int uid, int initialPid, int score, https://developer.android.com/reference/android/app/Notification notification, https://developer.android.com/reference/android/os/UserHandle user, long postTime) ` *This constructor is deprecated. Non-system apps should not need to create StatusBarNotifications.* |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/service/notification/StatusBarNotification` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#clone()() ` Creates and returns a copy of this object. |
| ` int` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getGroupKey()() ` A key that indicates the group with which this message ranks. |
| ` int` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getId()() ` The id supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getKey()() ` A unique instance key for this notification record. |
| ` https://developer.android.com/reference/android/app/Notification` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getNotification()() ` The `https://developer.android.com/reference/android/app/Notification` supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getOpPkg()() ` The package that posted the notification. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getOverrideGroupKey()() ` Returns the override group key. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPackageName()() ` The package that the notification belongs to. |
| ` long` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPostTime()() ` The time (in `https://developer.android.com/reference/java/lang/System#currentTimeMillis()` time) the notification was posted, which may be different than `https://developer.android.com/reference/android/app/Notification#when`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getTag()() ` The tag supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`, or null if no tag was specified. |
| ` int` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getUid()() ` The notifying app's (`https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPackageName()`'s) uid. |
| ` https://developer.android.com/reference/android/os/UserHandle` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getUser()() ` The `https://developer.android.com/reference/android/os/UserHandle` for whom this notification is intended. |
| ` int` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#getUserId()() ` *This method was deprecated in API level 21. Use `https://developer.android.com/reference/android/service/notification/StatusBarNotification#getUser()` instead.* |
| ` boolean` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#isAppGroup()() ` Returns true if application asked that this notification be part of a group. |
| ` boolean` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#isClearable()() ` Convenience method to check the notification's flags for either `https://developer.android.com/reference/android/app/Notification#FLAG_ONGOING_EVENT` or `https://developer.android.com/reference/android/app/Notification#FLAG_NO_CLEAR`. |
| ` boolean` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#isGroup()() ` Returns true if this notification is part of a group. |
| ` boolean` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#isOngoing()() ` Convenience method to check the notification's flags for `https://developer.android.com/reference/android/app/Notification#FLAG_ONGOING_EVENT`. |
| ` void` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#setOverrideGroupKey(java.lang.String)(https://developer.android.com/reference/java/lang/String overrideGroupKey) ` Sets the override group key. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#toString()() ` Returns a string representation of the object. |
| ` void` | ` https://developer.android.com/reference/android/service/notification/StatusBarNotification#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel out, int flags) ` Flatten this object in to a Parcel. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Fields

### CREATOR

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<StatusBarNotification> CREATOR
```

<br />

<br />

## Public constructors

### StatusBarNotification

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StatusBarNotification (Parcel in)
```

<br />

<br />

| Parameters ||
|---|---|
| `in` | `Parcel` <br /> |

### StatusBarNotification

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StatusBarNotification (String pkg, 
                String opPkg, 
                int id, 
                String tag, 
                int uid, 
                int initialPid, 
                int score, 
                Notification notification, 
                UserHandle user, 
                long postTime)
```

<br />

**This constructor is deprecated.**   

Non-system apps should not need to create StatusBarNotifications.

<br />

<br />

| Parameters ||
|---|---|
| `pkg` | `String` <br /> |
| `opPkg` | `String` <br /> |
| `id` | `int` <br /> |
| `tag` | `String` <br /> |
| `uid` | `int` <br /> |
| `initialPid` | `int` <br /> |
| `score` | `int` <br /> |
| `notification` | `Notification` <br /> |
| `user` | `UserHandle` <br /> |
| `postTime` | `long` <br /> |

## Public methods

### clone

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public StatusBarNotification clone ()
```

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object `x`, the expression:
>
> ```
> x.clone() != x
> ```
will be true, and that the expression:
>
> ```
> x.clone().getClass() == x.getClass()
> ```
will be `true`, but these are not absolute requirements. While it is typically the case that:
>
> ```
> x.clone().equals(x)
> ```
will be `true`, this is not an absolute requirement.

By convention, the returned object should be obtained by calling `super.clone`. If a class and all of its superclasses (except `Object`) obey this convention, it will be the case that `x.clone().getClass() == x.getClass()`.

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by `super.clone` before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by `super.clone` need to be modified.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/notification/StatusBarNotification` | a clone of this instance. <br /> |

### describeContents

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int describeContents ()
```

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getGroupKey

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getGroupKey ()
```

A key that indicates the group with which this message ranks.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getId

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getId ()
```

The id supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getKey

Added in [API level 20](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getKey ()
```

A unique instance key for this notification record.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getNotification

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Notification getNotification ()
```

The `https://developer.android.com/reference/android/app/Notification` supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification` | <br /> |

### getOpPkg

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getOpPkg ()
```

The package that posted the notification.

Might be different from `https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPackageName()` if the app owning the notification has a `https://developer.android.com/reference/android/app/NotificationManager#setNotificationDelegate(java.lang.String)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### getOverrideGroupKey

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getOverrideGroupKey ()
```

Returns the override group key.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getPackageName

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getPackageName ()
```

The package that the notification belongs to.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getPostTime

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getPostTime ()
```

The time (in `https://developer.android.com/reference/java/lang/System#currentTimeMillis()` time) the notification was posted, which may be different than `https://developer.android.com/reference/android/app/Notification#when`.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getTag

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getTag ()
```

The tag supplied to `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`, or null if no tag was specified.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### getUid

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getUid ()
```

The notifying app's (`https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPackageName()`'s) uid.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getUser

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public UserHandle getUser ()
```

The `https://developer.android.com/reference/android/os/UserHandle` for whom this notification is intended.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/UserHandle` | <br /> |

### getUserId

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getUserId ()
```

<br />

**This method was deprecated in API level 21.**   

Use `https://developer.android.com/reference/android/service/notification/StatusBarNotification#getUser()` instead.

Returns a userid for whom this notification is intended.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### isAppGroup

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isAppGroup ()
```

Returns true if application asked that this notification be part of a group.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isClearable

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isClearable ()
```

Convenience method to check the notification's flags for either `https://developer.android.com/reference/android/app/Notification#FLAG_ONGOING_EVENT` or `https://developer.android.com/reference/android/app/Notification#FLAG_NO_CLEAR`.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isGroup

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isGroup ()
```

Returns true if this notification is part of a group.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isOngoing

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isOngoing ()
```

Convenience method to check the notification's flags for `https://developer.android.com/reference/android/app/Notification#FLAG_ONGOING_EVENT`.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### setOverrideGroupKey

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOverrideGroupKey (String overrideGroupKey)
```

Sets the override group key.

<br />

| Parameters ||
|---|---|
| `overrideGroupKey` | `String` <br /> |

### toString

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### writeToParcel

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeToParcel (Parcel out, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `out` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |