> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Subscribe to push notification click events

> Subscribe to push notification click events in the Notifly SDK to run custom actions in your app when a user taps a notification.

> [tab] Android
>
> > [!NOTE]
> >
> > This feature requires Notifly Android SDK 1.5.0 or later.
>
> Use the Notifly Android SDK to subscribe to push notification click events and run custom actions in your app when a user taps a notification.
>
> ```kotlin theme={null}
>
>   package com.your.project
>
>   import android.app.Application
>   import android.util.Log
>   import tech.notifly.Notifly
>   import tech.notifly.push.interfaces.INotificationClickEvent
>   import tech.notifly.push.interfaces.INotificationClickListener
>
>   class SampleApplication : Application() {
>       override fun onCreate() {
>           super.onCreate()
>
>           // Optional: Set log level
>           Notifly.setLogLevel(Log.VERBOSE)
>
>           // Initialize Notifly SDK
>           Notifly.initialize(
>               context = applicationContext,
>               projectId = BuildConfig.NOTIFLY_PROJECT_ID,
>               username = BuildConfig.NOTIFLY_USERNAME,
>               // password is a placeholder for backward compatibility. Do not use a real password or API Secret Key.
>               password = BuildConfig.NOTIFLY_USERNAME,
>           )
>
>           // Subscribe for push notification click event
>           Notifly.addNotificationClickListener(object : INotificationClickListener {
>               override fun onClick(event: INotificationClickEvent) {
>                   Log.d("SampleApplication", "Notification clicked!")
>
>                   Log.d("SampleApplication", "Notification title: ${event.notification.title}")
>                   Log.d("SampleApplication", "Notification body: ${event.notification.body}")
>                   Log.d(
>                       "SampleApplication",
>                       "Notification custom data: ${event.notification.customData}"
>                   )
>               }
>           })
>       }
>   }
>
> ```

> [tab] Flutter
>
> > [!NOTE]
> >
> > This feature requires Notifly Flutter SDK 1.4.0 or later.
>
> Use the Notifly Flutter SDK to run custom actions when a user taps a push notification. The following example uses Go Router to navigate to a page when the user taps a notification. The listener in this example is registered only on Android.
>
> ```dart theme={null}
> import 'dart:io';
> import 'package:flutter/foundation.dart';
> import 'package:flutter/material.dart';
> import 'package:flutter_dotenv/flutter_dotenv.dart';
> import 'package:go_router/go_router.dart';
> import 'package:notifly_flutter/notifly_flutter.dart';
> import 'package:notifly_flutter_example/src/DetailPage.dart';
> import 'package:notifly_flutter_example/src/HomePage.dart';
>
> void main() async {
> await dotenv.load();
> runApp(const MyApp());
> }
>
> final router = GoRouter(
> routes: [
>     GoRoute(
>     path: '/',
>     builder: (context, state) => const HomePage(),
>     ),
>     GoRoute(
>     path: '/:id',
>     builder: (context, state) {
>         final pathId = state.pathParameters['id']!;
>         return DetailPage(id: pathId);
>     },
>     )
> ],
> );
>
> class MyApp extends StatefulWidget {
> const MyApp({super.key});
>
> @override
> _MyAppState createState() => _MyAppState();
> }
>
> class _MyAppState extends State<MyApp> {
> Future<void> initNotifly() async {
>     WidgetsFlutterBinding.ensureInitialized();
>
>     await NotiflyPlugin.initialize(
>     projectId: dotenv.env['NOTIFLY_PROJECT_ID']!,
>     username: dotenv.env['NOTIFLY_USERNAME']!,
>     // `password` is a placeholder for backward compatibility. Do not use a real password or API Secret Key.
>     password: dotenv.env['NOTIFLY_USERNAME']!,
>     );
>
>     print('🔥 [Flutter] NotiflyPlugin initialized');
>
>     if (!kIsWeb && Platform.isAndroid) {
>     await NotiflyPlugin.addNotificationClickListener((event) {
>         final customData = event.notification.customData;
>         if (customData != null) {
>         final routeId = customData['routeId'];
>         if (routeId != null) {
>             router.go('/$routeId');
>         }
>         }
>     });
>     }
> }
>
> @override
> void dispose() {
>     super.dispose();
> }
>
> @override
> void initState() {
>     super.initState();
>     initNotifly();
> }
>
> @override
> Widget build(BuildContext context) {
>     return MaterialApp.router(routerConfig: router);
> }
> }
> ```

## Push notification click event interface

> [tab] Android
>
> Access the `notification` object on `INotificationClickEvent` to inspect the notification that the user tapped.
>
> The following fields belong to `IPushNotification`.
>
> **IPushNotification properties**
>
> **androidNotificationId** `Int`
>
> The Android system notification ID. (Since 1.5.0)
>
> **campaignId** `String?`
>
> The ID of the Notifly campaign that sent the notification. (Since 1.5.0)
>
> **body** `String?`
>
> The notification body. (Since 1.5.0)
>
> **title** `String?`
>
> The notification title. (Since 1.5.0)
>
> **url** `String?`
>
> The URL to open when the user taps the notification. For notifications sent with the **Open App** action, the value is `null`. (Since 1.5.0)
>
> **customData** `HashMap\<String, String\>`
>
> Custom key-value data included in the FCM message's `data` field. You can configure this data in the Notifly console. (Since 1.5.0)
>
> **imageUrl** `String?`
>
> The URL of the image included in the notification. (Since 1.5.0)
>
> **importance** `Importance?`
>
> `Importance` is defined in `tech.notifly.push.impl.Importance`. The value is `Importance.HIGH`, `Importance.NORMAL`, or `Importance.LOW`, or `null` if no importance is set. (Since 1.5.0)
>
> **notiflyMessageId** `String?`
>
> The message ID generated by the Notifly server. (Since 1.5.0)
>
> **rawPayload** `String`
>
> The raw FCM data payload, returned as a JSON string. (Since 1.5.0)
>
> **sentTime** `Long`
>
> The time when FCM sent the notification, in milliseconds since the Unix epoch. (Since 1.5.0)
>
> **ttl** `Int`
>
> The notification's time to live (TTL), in seconds. (Since 1.5.0)

> [tab] Flutter
>
> Access the `notification` member of `OSNotificationClickEvent` to inspect the notification that the user tapped. The following type definitions show the fields. Constructors and implementations are omitted.
>
> ```dart theme={null}
> /// Callback for handling notification clicks.
> typedef NotificationClickListener = void Function(
> OSNotificationClickEvent event,
> );
>
> /// Represents notification importance. Used only on Android.
> enum OSNotificationImportance {
> /// The notification is of low importance.
> low,
>
> /// The notification is of normal importance.
> normal,
>
> /// The notification is of high importance.
> high,
> }
>
> /// Represents a notification received from the Notifly service.
> class OSNotification extends JSONStringRepresentable {
> /// The Notifly message ID of the notification.
> String? notiflyMessageId;
>
> /// (Only Android) The Android system notification ID of the notification.
> int? androidNotificationId;
>
> /// Notifly campaign ID where the notification was sent from.
> String? campaignId;
>
> /// Notification title
> String? title;
>
> /// Notification body
> String? body;
>
> /// (Only Android) Importance of the notification.
> OSNotificationImportance? importance;
>
> /// URL included in the notification.
> String? url;
>
> /// URL to the image included in the notification.
> String? imageUrl;
>
> /// Sent time of the notification in milliseconds since epoch
> int? sentTime;
>
> /// TTL of the notification in seconds
> int? ttl;
>
> /// Customized data included in the notification.
> Map<String, dynamic>? customData;
>
> /// Raw payload of the notification.
> Map<String, dynamic>? rawPayload;
> }
>
> /// Represents a notification click event.
> class OSNotificationClickEvent {
> OSNotification notification;
> }
>
> ```
>
> The following fields belong to `OSNotification`.
>
> **OSNotification properties**
>
> **androidNotificationId** `int?`
>
> The Android system notification ID. (Since 1.4.0)
>
> **campaignId** `String?`
>
> The ID of the Notifly campaign that sent the notification. (Since 1.4.0)
>
> **body** `String?`
>
> The notification body. (Since 1.4.0)
>
> **title** `String?`
>
> The notification title. (Since 1.4.0)
>
> **url** `String?`
>
> The URL to open when the user taps the notification. For notifications sent with the **Open App** action, the value is `null`. (Since 1.4.0)
>
> **customData** `Map\<String, dynamic\>?`
>
> Custom key-value data included in the FCM message's `data` field. You can configure this data in the Notifly console. (Since 1.4.0)
>
> **imageUrl** `String?`
>
> The URL of the image included in the notification. (Since 1.4.0)
>
> **importance** `OSNotificationImportance?`
>
> `OSNotificationImportance.high`, `OSNotificationImportance.normal`, or `OSNotificationImportance.low`. Available only on Android. (Since 1.4.0)
>
> **notiflyMessageId** `String?`
>
> The message ID generated by the Notifly server. (Since 1.4.0)
>
> **rawPayload** `Map\<String, dynamic\>?`
>
> The raw FCM data payload, decoded into a map. (Since 1.4.0)
>
> **sentTime** `int?`
>
> The time when FCM sent the notification, in milliseconds since the Unix epoch. (Since 1.4.0)
>
> **ttl** `int?`
>
> The notification's time to live (TTL), in seconds. (Since 1.4.0)

> [tab] React Native
>
> Access the `notification` member of `OSNotificationClickEvent` to inspect the notification that the user tapped.
>
> ```TypeScript theme={null}
> export type NotificationClickListener = (
>   event: OSNotificationClickEvent,
> ) => void;
>
> export declare enum OSNotificationImportance {
>   LOW = 0,
>   NORMAL = 1,
>   HIGH = 2,
> }
>
> export interface OSNotificationClickEvent {
>   notification: OSNotification;
> }
>
> export interface OSNotification {
>   notiflyMessageId?: string;
>   androidNotificationId?: number;
>   campaignId?: string;
>   title?: string;
>   body?: string;
>   importance?: OSNotificationImportance;
>   url?: string;
>   imageUrl?: string;
>   sentTime?: number;
>   ttl?: number;
>   customData?: {
>     [key: string]: any;
>   };
>   rawPayload?: {
>     [key: string]: any;
>   };
> }
> ```
>
> The following fields belong to `OSNotification`.
>
> **OSNotification properties**
>
> **androidNotificationId** `number | undefined`
>
> The Android system notification ID. (Since 3.2.0)
>
> **campaignId** `string | undefined`
>
> The ID of the Notifly campaign that sent the notification. (Since 3.2.0)
>
> **body** `string | undefined`
>
> The notification body. (Since 3.2.0)
>
> **title** `string | undefined`
>
> The notification title. (Since 3.2.0)
>
> **url** `string | undefined`
>
> The URL to open when the user taps the notification. For notifications sent with the **Open App** action, this property is omitted. (Since 3.2.0)
>
> **customData** `\{[key: string]: any\} | undefined`
>
> Custom key-value data included in the FCM message's `data` field. You can configure this data in the Notifly console. (Since 3.2.0)
>
> **imageUrl** `string | undefined`
>
> The URL of the image included in the notification. (Since 3.2.0)
>
> **importance** `OSNotificationImportance | undefined`
>
> `OSNotificationImportance.HIGH`, `OSNotificationImportance.NORMAL`, or `OSNotificationImportance.LOW`. Available only on Android. (Since 3.2.0)
>
> **notiflyMessageId** `string | undefined`
>
> The message ID generated by the Notifly server. (Since 3.2.0)
>
> **rawPayload** `\{[key: string]: any\} | undefined`
>
> The raw FCM data payload, parsed into an object. If parsing fails, the SDK returns the original payload. (Since 3.2.0)
>
> **sentTime** `number | undefined`
>
> The time when FCM sent the notification, in milliseconds since the Unix epoch. (Since 3.2.0)
>
> **ttl** `number | undefined`
>
> The notification's time to live (TTL), in seconds. (Since 3.2.0)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.