푸시 메시지 연동

1. Firebase 프로젝트 연동하기

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

자세한 내용은 Android FCM 연동을 참고해주세요.

2. Firebase Cloud Messaging SDK 연동하기

Firebase Cloud Messaging 설치 가이드 를 참고하여 안드로이드 앱 설정을 완료해주세요.

3. 핵클 SDK와 연동하기

SDK 연동 를 참고해서 핵클 SDK 의존성을 추가하고 SDK를 초기화 합니다.

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

4. 푸시 메시지 테스트

토큰 확인

발송 테스트

5. 푸시 메시지 수신

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

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

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


(Advanced) 딥링크 이동

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

안드로이드 딥링크에 대한 자세한 사항은 안드로이드 딥링크 가이드 에서 확인 가능합니다.

import android.app.Activity
import android.content.Intent
import android.os.Bundle

class ExampleActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstance)
        if (intent != null && !intent.dataString.isNullOrEmpty()) {
            //  Do something ...
            println("link : ${intent?.dataString}")
        }
    }
    
    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        setIntent(intent)
        if (intent != null && !intent.dataString.isNullOrEmpty()) {
            //  Do something ...
            println("link : ${intent?.dataString}")
        }
    }
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;

public class ExampleActivity extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if (intent != null && intent.getDataString() != null) {
            String text = String.format("link : %s", intent.getDataString());
            System.out.println(text);
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        if (intent != null && intent.getDataString() != null) {
            String text = String.format("link : %s", intent.getDataString());
            System.out.println(text);
        }
    }
}

(Advanced) 푸시 메시지 아이콘 변경

📘

지원 SDK 버전

Android SDK 2.57.0 버전 이상

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

small_icon, large_icon, color에 대한 자세한 사항은 안드로이드 푸시 디자인 가이드 에서 확인 가능합니다.

key설명
io_hackle_android_default_notification_small_iconsmall icon을 설정합니다.
io_hackle_android_default_notification_large_iconlarge icon을 설정합니다.
io_hackle_android_default_notification_colorsmall icon background 색상을 설정합니다.

Example

<?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:name=".MainApplication"
        >
       ...
       <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>