Skip to content

Notifications#

flet_onesignal.notifications.OneSignalNotifications #

OneSignal Notifications namespace.

Provides methods for managing push notification permissions, display, and lifecycle.

Functions#

can_request_permission async #

can_request_permission(timeout: float = 25) -> bool

Check if the app can request notification permission.

Returns True if the device has not been prompted for push notification permission already.

Returns:

Type Description
bool

True if permission can be requested, False if already prompted.

clear_all async #

clear_all() -> None

Remove all OneSignal notifications from the notification shade.

display async #

display(notification_id: str) -> None

Allow a notification to be displayed after calling prevent_default.

Parameters:

Name Type Description Default
notification_id str

The notification ID from the event.

required

get_permission async #

get_permission(timeout: float = 25) -> bool

Get the current notification permission status.

Returns:

Type Description
bool

True if notifications are permitted, False otherwise.

prevent_default async #

prevent_default(notification_id: str) -> None

Prevent a notification from being displayed when received in foreground.

Call this from the on_foreground_will_display event handler to suppress the notification display.

Parameters:

Name Type Description Default
notification_id str

The notification ID from the event.

required

register_for_provisional_authorization async #

register_for_provisional_authorization(
    timeout: float = 25,
) -> bool

Request provisional authorization for notifications (iOS only).

Provisional authorization allows sending notifications quietly to the Notification Center without prompting the user first.

Returns:

Type Description
bool

True if authorization was granted, False otherwise.

remove_grouped_notifications async #

remove_grouped_notifications(group: str) -> None

Remove a group of notifications (Android only).

Parameters:

Name Type Description Default
group str

The notification group key to remove.

required

remove_notification async #

remove_notification(notification_id: int) -> None

Remove a specific notification (Android only).

Parameters:

Name Type Description Default
notification_id int

The Android notification ID to remove.

required

request_permission async #

request_permission(
    fallback_to_settings: bool = True, timeout: float = 25
) -> bool

Request permission to send push notifications.

This will display the native system prompt to request push notification permission.

Parameters:

Name Type Description Default
fallback_to_settings bool

If True and permission was previously denied, opens the app settings instead.

True
timeout float

Maximum time to wait for user response (in seconds).

25

Returns:

Type Description
bool

True if permission was granted, False otherwise.