# Android 푸시 메시지 연동

{% stepper %}
{% step %}
**Firebase 프로젝트 연동하기**

안드로이드 앱에서 푸시 메시지를 사용하기 위해서는 핵클 워크스페이스와 Firebase 프로젝트 연동 설정이 필요합니다.

자세한 내용은 [Android FCM 연동](/external-link/crm-channels/fcm-integration.md)을 참고해주세요.
{% endstep %}

{% step %}
**Firebase Cloud Messaging SDK 연동하기**

[Firebase SDK 연동 가이드](https://firebase.google.com/docs/android/setup) 및 [Firebase Cloud Messaging 설치 가이드](https://firebase.google.com/docs/cloud-messaging/android/client)를 참고하여 안드로이드 앱 설정을 완료해주세요.
{% endstep %}

{% step %}
**핵클 SDK와 연동하기**

[SDK 연동](/development-guide/flutter.md)을 참고해서 핵클 SDK 의존성을 추가하고 SDK를 초기화 합니다.

앱 실행 시 자동으로 푸시 토큰이 등록 됩니다.

{% hint style="info" %}
정상적으로 SDK 연동이 완료되면 자동으로 푸시 토큰 수집이 되고, 푸시 수신, 푸시 클릭 처리가 가능합니다.
{% endhint %}
{% endstep %}

{% step %}
**푸시 메시지 테스트**

**토큰 확인**

* [사용자 식별자 확인하기 가이드](https://docs.hackle.io/development-guide/flutter/push-message/pages/6gdkIjtMX65vkClagMl7#사용자-식별자-확인하기)를 통해 안드로이드 기기에 설정된 토큰을 확인할 수 있습니다.
* [사용자 조회 가이드](/user-view/user-profile.md)를 통해 특정 사용자에 할당 된 안드로이드 푸시 토큰을 확인할 수 있습니다.

**발송 테스트**

* [푸시 메시지 테스트 발송 가이드](/crm-marketing/push-message-guide/create-campaign.md#id-3-1)를 참고하여 푸시 메시지를 안드로이드 기기에서 확인합니다.
  {% endstep %}

{% step %}
**푸시 메시지 수신**

푸시 수신 시 status bar와 알림센터에 아이콘이 표시됩니다.

* 갤럭시 안드로이드 스마트폰 환경에서는 앱 아이콘이 표시됩니다.
* 일반 안드로이드 스마트폰 or 시뮬레이터 환경에서는 흰색 원 아이콘이 표시됩니다.
* 푸시메시지 아이콘 변경 기능을 이용한 경우 변경한 아이콘이 표시됩니다.
  {% endstep %}
  {% endstepper %}

## 딥링크 이동

핵클 푸시 메시지는 클릭 시 딥링크 이동을 지원합니다.

푸시 메시지를 통해 해당 액티비티가 열리는 경우 아래와 같은 방법으로 열린 딥링크 정보를 확인할수 있습니다.

Flutter 딥링크에 대한 자세한 사항은 [Flutter 딥링크 가이드](https://docs.flutter.dev/ui/navigation/deep-linking) 에서 확인 가능합니다.

## 푸시 메시지 아이콘 변경

{% hint style="info" %}
Flutter SDK 2.22.0 버전 이상에서 지원하는 기능입니다.
{% endhint %}

{% hint style="warning" %}
구글 정책으로 일반 안드로이드 스마트폰에서는 색상이 포함된 아이콘을 푸시 아이콘으로 설정할 수 없습니다.
{% endhint %}

핵클 푸시 메시지는 푸시 아이콘 변경을 지원합니다. `AndroidManifest.xml`에 미리 예약된 key에 리소스를 할당하면 앱 내 로컬 리소스를 이용해서 푸시 아이콘을 변경할 수 있습니다.

푸시 아이콘에 사용할 이미지와 색상 리소스는 Android Resource에 추가해야 합니다.

{% hint style="info" %}
small\_icon, large\_icon, color에 대한 자세한 사항은 [안드로이드 푸시 디자인 가이드](https://developer.android.com/design/ui/mobile/guides/home-screen/notifications?hl=ko#notification-header) 에서 확인 가능합니다.
{% endhint %}

<table><thead><tr><th width="360">key</th><th>설명</th></tr></thead><tbody><tr><td><code>io_hackle_android_default_notification_small_icon</code></td><td>small icon을 설정합니다.</td></tr><tr><td><code>io_hackle_android_default_notification_large_icon</code></td><td>large icon을 설정합니다.</td></tr><tr><td><code>io_hackle_android_default_notification_color</code></td><td>small icon background 색상을 설정합니다.</td></tr></tbody></table>

#### Example

```xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <application
        android:label="flutter_app"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

       ...
       <meta-data
            android:name="io_hackle_android_default_notification_small_icon"
            android:resource="@drawable/ic_push_small"/>

       <meta-data
            android:name="io_hackle_android_default_notification_large_icon"
            android:resource="@drawable/ic_push_large"/>

       <meta-data
            android:name="io_hackle_android_default_notification_color"
            android:resource="@color/pie" />
       ...
    </application>
</manifest>
```

### 대시보드에서 푸시 메시지 아이콘 수정

대시보드에서 푸시 아이콘을 설정 한 경우 푸시의 large icon을 수정합니다.

로컬 리소스로 푸시 아이콘을 설정하고 대시보드에서도 푸시 아이콘을 송신 한 경우 대시보드에 설정 한 아이콘을 사용합니다.

## 푸시 채널 지원

{% hint style="info" %}
Flutter SDK 2.23.0 버전 이상에서 지원하는 기능입니다.
{% endhint %}

핵클 푸시 메시지를 이용하면 앱 내 미리 선언한 채널로 푸시를 수신받을 수 있습니다. 앱에 존재하지 않는 채널 ID로 푸시 수신 시 핵클에서 제공하는 기본 채널로 푸시를 수신받습니다.

{% hint style="info" %}
앱에 푸시 채널을 추가하는 자세한 방법은 [안드로이드 개발자 문서](https://developer.android.com/develop/ui/views/notifications/channels?hl=ko) 에서 확인 가능합니다.

만약 iOS와 같이 푸시 수신 시 알림 팝업을 띄우고 싶다면 푸시 채널의 중요도를 `IMPORTANCE_HIGH`로 설정해주세요.
{% endhint %}

#### Example

아래는 MainActivity 클래스의 `onCreate` 함수에서 채널을 만드는 예제입니다.

```kotlin
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
import io.flutter.embedding.android.FlutterActivity


class MainActivity: FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            createNotificationChannel(applicationContext, "importance", "importance", NotificationManager.IMPORTANCE_HIGH)
        }
    }

    @RequiresApi(Build.VERSION_CODES.O)
    private fun createNotificationChannel(context: Context, channelId: String, channelName: String, importance: Int) {
        val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        if (notificationManager.getNotificationChannel(channelId) != null) {
            return
        }

        val channel = NotificationChannel(
            channelId,
            channelName,
            importance
        )
        notificationManager.createNotificationChannel(channel)
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/flutter/push-message/flutter-android-push-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
