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

# プッシュ通知のクリックイベントを購読する

> Notifly SDKでプッシュ通知のクリックイベントを購読し、ユーザーが通知をタップしたときにアプリ内で独自の処理を実行する方法を説明します。

> [tab] Android
>
> > [!NOTE]
> >
> > この機能はNotifly Android SDK 1.5.0以降で利用できます。
>
> Notifly Android SDKにクリックリスナーを登録すると、ユーザーが通知をタップしたときにアプリ内で独自の処理を実行できます。
>
> ```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()
>
>           // 任意でログレベルを設定します
>           Notifly.setLogLevel(Log.VERBOSE)
>
>           // Notifly SDKを初期化します
>           Notifly.initialize(
>               context = applicationContext,
>               projectId = BuildConfig.NOTIFLY_PROJECT_ID,
>               username = BuildConfig.NOTIFLY_USERNAME,
>               // passwordは後方互換性のためのプレースホルダーです。実際のパスワードやAPI Secret Keyを設定しないでください。
>               password = BuildConfig.NOTIFLY_USERNAME,
>           )
>
>           // プッシュ通知のクリックイベントを購読します
>           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]
> >
> > この機能はNotifly Flutter SDK 1.4.0以降で利用できます。
>
> Notifly Flutter SDKでは、ユーザーがプッシュ通知をタップしたときに独自の処理を実行できます。次の例では、Go Routerを使用して通知のタップ時に指定のページに移動します。この例では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`は後方互換性のためのプレースホルダーです。実際のパスワードや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);
> }
> }
> ```

## プッシュ通知のクリックイベントのインターフェース

> [tab] Android
>
> `INotificationClickEvent`の`notification`オブジェクトから、ユーザーがタップした通知の情報を取得できます。
>
> `IPushNotification`の各プロパティを説明します。
>
> **IPushNotificationのプロパティ**
>
> **androidNotificationId** `Int`
>
> Androidシステムの通知IDです（1.5.0以降）。
>
> **campaignId** `String?`
>
> 通知を送信したNotiflyキャンペーンのIDです（1.5.0以降）。
>
> **body** `String?`
>
> 通知の本文です（1.5.0以降）。
>
> **title** `String?`
>
> 通知のタイトルです（1.5.0以降）。
>
> **url** `String?`
>
> 通知をタップしたときに開くURLです。「アプリを起動」アクションで送信した通知では、値は`null`になります（1.5.0以降）。
>
> **customData** `HashMap\<String, String\>`
>
> FCMメッセージの`data`フィールドに含まれるカスタムデータのキーと値のペアです。Notiflyコンソールで設定できます（1.5.0以降）。
>
> **imageUrl** `String?`
>
> 画像付きプッシュ通知に含まれる画像のURLです（1.5.0以降）。
>
> **importance** `Importance?`
>
> `Importance`は`tech.notifly.push.impl.Importance`で定義されています。値は`Importance.HIGH`、`Importance.NORMAL`、`Importance.LOW`のいずれかです。重要度が設定されていない場合は`null`になります（1.5.0以降）。
>
> **notiflyMessageId** `String?`
>
> Notiflyサーバーが生成するメッセージIDです（1.5.0以降）。
>
> **rawPayload** `String`
>
> FCMメッセージの`data`フィールドの生データです。JSON文字列として返されます（1.5.0以降）。
>
> **sentTime** `Long`
>
> FCMサーバーが通知を送信した時刻です。Unixエポックからのミリ秒数で表します（1.5.0以降）。
>
> **ttl** `Int`
>
> 通知の有効期間（TTL）です。秒単位で表します（1.5.0以降）。

> [tab] Flutter
>
> `OSNotificationClickEvent`の`notification`メンバーから、ユーザーがタップした通知の情報を取得できます。次の型定義はプロパティを示したものです。コンストラクターと実装は省略しています。
>
> ```dart theme={null}
> /// 通知のクリックを処理するコールバックです。
> typedef NotificationClickListener = void Function(
> OSNotificationClickEvent event,
> );
>
> /// 通知の重要度を表します。Androidでのみ利用できます。
> enum OSNotificationImportance {
> /// 通知の重要度は低です。
> low,
>
> /// 通知の重要度は通常です。
> normal,
>
> /// 通知の重要度は高です。
> high,
> }
>
> /// Notiflyサービスから受信した通知を表します。
> class OSNotification extends JSONStringRepresentable {
> /// 通知のNotiflyメッセージIDです。
> String? notiflyMessageId;
>
> /// Androidシステムの通知IDです。Androidでのみ利用できます。
> int? androidNotificationId;
>
> /// 通知を送信したNotiflyキャンペーンのIDです。
> String? campaignId;
>
> /// 通知のタイトルです
> String? title;
>
> /// 通知の本文です
> String? body;
>
> /// 通知の重要度です。Androidでのみ利用できます。
> OSNotificationImportance? importance;
>
> /// 通知に含まれるURLです。
> String? url;
>
> /// 通知に含まれる画像のURLです。
> String? imageUrl;
>
> /// 通知の送信時刻です。Unixエポックからのミリ秒数で表します
> int? sentTime;
>
> /// 通知のTTLです。秒単位で表します
> int? ttl;
>
> /// 通知に含まれるカスタムデータです。
> Map<String, dynamic>? customData;
>
> /// 通知の生のペイロードです。
> Map<String, dynamic>? rawPayload;
> }
>
> /// 通知のクリックイベントを表します。
> class OSNotificationClickEvent {
> OSNotification notification;
> }
>
> ```
>
> `OSNotification`の各プロパティを説明します。
>
> **OSNotificationのプロパティ**
>
> **androidNotificationId** `int?`
>
> Androidシステムの通知IDです（1.4.0以降）。
>
> **campaignId** `String?`
>
> 通知を送信したNotiflyキャンペーンのIDです（1.4.0以降）。
>
> **body** `String?`
>
> 通知の本文です（1.4.0以降）。
>
> **title** `String?`
>
> 通知のタイトルです（1.4.0以降）。
>
> **url** `String?`
>
> 通知をタップしたときに開くURLです。「アプリを起動」アクションで送信した通知では、値は`null`になります（1.4.0以降）。
>
> **customData** `Map\<String, dynamic\>?`
>
> FCMメッセージの`data`フィールドに含まれるカスタムデータのキーと値のペアです。Notiflyコンソールで設定できます（1.4.0以降）。
>
> **imageUrl** `String?`
>
> 画像付きプッシュ通知に含まれる画像のURLです（1.4.0以降）。
>
> **importance** `OSNotificationImportance?`
>
> `OSNotificationImportance.high`、`OSNotificationImportance.normal`、`OSNotificationImportance.low`のいずれかです。Androidでのみ利用できます（1.4.0以降）。
>
> **notiflyMessageId** `String?`
>
> Notiflyサーバーが生成するメッセージIDです（1.4.0以降）。
>
> **rawPayload** `Map\<String, dynamic\>?`
>
> FCMメッセージの`data`フィールドの生データです。デコードされたMapとして返されます（1.4.0以降）。
>
> **sentTime** `int?`
>
> FCMサーバーが通知を送信した時刻です。Unixエポックからのミリ秒数で表します（1.4.0以降）。
>
> **ttl** `int?`
>
> 通知の有効期間（TTL）です。秒単位で表します（1.4.0以降）。

> [tab] React Native
>
> `OSNotificationClickEvent`の`notification`メンバーから、ユーザーがタップした通知の情報を取得できます。
>
> ```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;
>   };
> }
> ```
>
> `OSNotification`の各プロパティを説明します。
>
> **OSNotificationのプロパティ**
>
> **androidNotificationId** `number | undefined`
>
> Androidシステムの通知IDです（3.2.0以降）。
>
> **campaignId** `string | undefined`
>
> 通知を送信したNotiflyキャンペーンのIDです（3.2.0以降）。
>
> **body** `string | undefined`
>
> 通知の本文です（3.2.0以降）。
>
> **title** `string | undefined`
>
> 通知のタイトルです（3.2.0以降）。
>
> **url** `string | undefined`
>
> 通知をタップしたときに開くURLです。「アプリを起動」アクションで送信した通知では、このプロパティは省略されます（3.2.0以降）。
>
> **customData** `\{[key: string]: any\} | undefined`
>
> FCMメッセージの`data`フィールドに含まれるカスタムデータのキーと値のペアです。Notiflyコンソールで設定できます（3.2.0以降）。
>
> **imageUrl** `string | undefined`
>
> 画像付きプッシュ通知に含まれる画像のURLです（3.2.0以降）。
>
> **importance** `OSNotificationImportance | undefined`
>
> `OSNotificationImportance.HIGH`、`OSNotificationImportance.NORMAL`、`OSNotificationImportance.LOW`のいずれかです。Androidでのみ利用できます（3.2.0以降）。
>
> **notiflyMessageId** `string | undefined`
>
> Notiflyサーバーが生成するメッセージIDです（3.2.0以降）。
>
> **rawPayload** `\{[key: string]: any\} | undefined`
>
> FCMメッセージの`data`フィールドの生データです。パースされたオブジェクトとして返されます。パースに失敗した場合は、元のペイロードが返されます（3.2.0以降）。
>
> **sentTime** `number | undefined`
>
> FCMサーバーが通知を送信した時刻です。Unixエポックからのミリ秒数で表します（3.2.0以降）。
>
> **ttl** `number | undefined`
>
> 通知の有効期間（TTL）です。秒単位で表します（3.2.0以降）。


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