개발자 가이드
사용자 가이드개발자 가이드API 가이드🏠
한국어
한국어
  • 홈
  • 공통
    • 통합 ID 연동 시나리오
    • 상수
    • FAQ
  • 플랫폼 별 가이드
    • Android
      • 연동하기
      • 이벤트
      • 유저 식별 정보 설정
      • 유저 프로필 설정
      • 액션
        • 푸시
        • 인앱메시지
        • 알림톡
        • 문자
      • 개인 정보 보호
        • 개인 정보 보호 지원
        • Google Play의 데이터 공개 요건 준비
      • 릴리즈 노트
    • iOS
      • 연동하기
      • 이벤트
      • 유저 식별 정보 설정
      • 유저 프로필 설정
      • 액션
        • 푸시
        • 인앱메시지
        • 알림톡
        • 문자
      • 릴리즈 노트
    • Hybrid App
      • 연동하기
    • Web
      • 연동하기
      • 이벤트
      • 유저 식별 정보 설정
      • 유저 프로필 설정
      • 액션
        • 인앱메시지
        • 알림톡
        • 문자
      • 고급 사용 사례
        • 부가 설정
      • 릴리즈 노트
Powered by GitBook
On this page
  • 시작하기 전에
  • 푸시 알림 수신 허용 유무 등록하기
  • 콘솔에서 Firebase 정보 등록하기
  • Support Library 의존성 추가하기
  • Firebase Cloud Messaging 연동
  • Android 프로젝트에 Firebase 추가하기
  • Firebase Cloud Messaging 설정하기
  • 토큰을 DFINERY에 연동하기
  • 현재 등록 토큰 가져오기 시 연동
  • 토큰 생성 모니터링 시 연동
  • 푸시 알림 채널을 DFINERY에 연동하기
  • 푸시 알림 채널 생성
  • 생성한 푸시 알림 채널 ID 등록
  • 푸시 알림 아이콘 설정하기
  • 푸시 알림 강조색 지정하기
  • 푸시 알림 수신 처리하기
  • 푸시 알림 클릭 처리하기
  • 완료
  • 더 알아보기
  • 알림 채널 생성 따라해보기
  • Firebase 사용자 인증 정보 비공개 키 파일 발급 따라해보기
  • 발신자 ID 확인 방법
  1. 플랫폼 별 가이드
  2. Android
  3. 액션

푸시

Previous액션Next인앱메시지

Last updated 11 days ago

DFINERY는 Firebase Cloud Messaging을 사용하여 푸시를 수신받으므로 어플리케이션에서 Firebase 연동이 필요합니다.

시작하기 전에

푸시 알림 수신 허용 유무 등록하기

광고성 목적이 있는 푸시의 경우 에 따라 유저에게 사전 수신동의를 받아야 합니다. 유저에게 푸시 알림이 허용되었다는 정보를 DFINERY에 등록하기 위해서 다음의 일련의 작업을 수행하여 주시기 바랍니다.

  1. 유저에게 푸시 알림 허용에 대한 고지하기

  2. 유저의 허용/거부 의사에 대한 값을 유저 프로필에 등록

를 참고하여 유저가 동의한 항목에 대해 값을 입력해주시기 바랍니다. 아래 코드는 푸시 채널에 관해 정보성, 광고성 수신 동의를 허용한 예시입니다.

Map<String, Object> consents = new HashMap<>();
consents.put(DFUserProfile.PUSH_OPTIN, true);
consents.put(DFUserProfile.PUSH_ADS_OPTIN, true);
DfineryProperties.setUserProfiles(consents);
val consents = mapOf<String, Any>(
    DFUserProfile.PUSH_OPTIN to true, 
    DFUserProfile.PUSH_ADS_OPTIN to true
)
DfineryProperties.setUserProfiles(consents)

콘솔에서 Firebase 정보 등록하기

에서 부가설정/채널 부가 설정/푸시/Android 설정관리에 들어가 발신자 ID를 입력하고 JSON 형식의 Firebase 사용자 인증 정보 비공개 키 파일을 업로드합니다.

Support Library 의존성 추가하기

  1. 앱의 모듈 디렉터리 내에 있는 build.gradle 파일을 엽니다.

  2. dependencies에 Support Library 의존성을 추가합니다.

 dependencies {
    implementation 'androidx.core:core:1.9.0'
}
 dependencies {
    implementation ("androidx.core:core:1.9.0")
}

Firebase Cloud Messaging 연동

Android 프로젝트에 Firebase 추가하기

Firebase Cloud Messaging 설정하기

토큰을 DFINERY에 연동하기

Firebase에서 발급된 토큰을 DFINERY에 연동하기 위해서 다음과 같이 작성해 주시기 바랍니다.

현재 등록 토큰 가져오기 시 연동

FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
    @Override
    public void onComplete(@NonNull Task<String> task) {
        if (!task.isSuccessful()) {
            Log.w(TAG, "Fetching FCM registration token failed", task.getException());
            return;
        }

        // Get new FCM registration token
        String token = task.getResult();
        DfineryProperties.setPushToken(token);
    }
});
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
    if (!task.isSuccessful) {
        Log.w(TAG, "Fetching FCM registration token failed", task.exception)
        return@OnCompleteListener
    }

    // Get new FCM registration token
    val token = task.result
    DfineryProperties.setPushToken(token)
})

토큰 생성 모니터링 시 연동

@Override
public void onNewToken(@NonNull String token) {
    Log.d(TAG, "Refreshed token: " + token);
    DfineryProperties.setPushToken(token);
}
override fun onNewToken(token: String) {
    Log.d(TAG, "Refreshed token: $token")
    DfineryProperties.setPushToken(token)
}

푸시 알림 채널을 DFINERY에 연동하기

푸시 알림 채널 생성

생성한 푸시 알림 채널 ID 등록

DfineryConfig의 setDefaultNotificationChannelId() 메소드를 사용하거나 res/values/dfinery.xml을 사용하여 생성한 알림 채널의 ID를 등록합니다.

DfineryConfig config = new DfineryConfig.Builder()
    .setDefaultNotificationChannelId("NOTIFICATION_CHANNEL_ID")
    .build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
val config = DfineryConfig.Builder()
    .setDefaultNotificationChannelId("NOTIFICATION_CHANNEL_ID")
    .build()
Dfinery.getInstance().init(this, "SERVICE_KEY", config)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="com_igaworks_dfinery_default_notification_channel_id" translatable="false">
      NOTIFICATION_CHANNEL_ID
    </string>
</resources>

푸시 알림 아이콘 설정하기

푸시 알림을 표시하기 위해서는 아이콘 설정이 필요합니다. DfineryConfig의 setNotificationIcon() 메소드를 사용하거나 res/values/dfinery.xml을 사용하여 아이콘을 설정해주시기 바랍니다.

알림 자체는 물론 상단 상태 표시줄에도 표시되는 아이콘이기 때문에 특정 단말기에서는 이미지의 색상이 무시될 수 있으니 72x72px의 알파 채널을 가진 이미지를 권장합니다.

DfineryConfig config = new DfineryConfig.Builder()
    .setNotificationIcon(R.drawable.icon)
    .build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
val config = DfineryConfig.Builder()
    .setNotificationIcon(R.drawable.icon)
    .build()
Dfinery.getInstance().init(this, "SERVICE_KEY", config)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <drawable name="com_igaworks_dfinery_notification_icon">
      @drawable/NOTIFICATION_ICON_DRAWABLE 
    </drawable>
</resources>

푸시 알림 강조색 지정하기

알림 아이콘 강조색은 setNotificationAccentColor(int argb)를 호출하여 변경할 수 있습니다. 색상을 지정하지 않으면 시스템 기본 색상으로 표시됩니다.

푸시 알림 강조색은 사용 중인 OS 버전과 런처에 따라 다르게 표시될 수 있습니다.

DfineryConfig config = new DfineryConfig.Builder()
    .setNotificationAccentColor(Color.parseColor("#0c8900"))
    .build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
val config = DfineryConfig.Builder()
    .setNotificationAccentColor(Color.parseColor("#0c8900"))
    .build()
Dfinery.getInstance().init(this, "SERVICE_KEY", config)

푸시 알림 수신 처리하기

@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    if(Dfinery.getInstance().handleRemoteMessage(getApplicationContext(), remoteMessage.getData())){
        //dfinery push
    }else{
        //This is not a push notification sent from Dfinery.
    }
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
  if(Dfinery.getInstance().handleRemoteMessage(applicationContext, remoteMessage.getData())){
        //dfinery push
    }else{
        //This is not a push notification sent from Dfinery.
    }
}

푸시 알림 클릭 처리하기

해당하는 Activity에 setIntent() 코드를 추가해 주시기 바랍니다.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); 
}
override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    setIntent(intent)
}

완료

푸시 설정이 완료되었습니다.

더 알아보기

알림 채널 생성 따라해보기

1. 알림 채널을 생성합니다.

  • 첫번째 파라미터 id는 알림 채널의 ID를 의미합니다.

  • 두번째 파라미터 name은 알림 채널의 이름을 의미합니다. 해당 값은 설정/알림에서 유저에게 노출됩니다.

NotificationChannel notificationChannel = new NotificationChannel("NOTIFICATION_CHANNEL_ID", "NOTIFICATION_CHANNEL_NAME", NotificationManager.IMPORTANCE_HIGH);
val notificationChannel = NotificationChannel("NOTIFICATION_CHANNEL_ID", "NOTIFICATION_CHANNEL_NAME", NotificationManager.IMPORTANCE_HIGH)

2. 알림 채널의 설명을 설정합니다. (Optional)

해당 값은 설정/알림에서 유저에게 노출됩니다.

notificationChannel.setDescription("NOTIFICATION_CHANNEL_DESCRIPTION");
notificationChannel.description = "NOTIFICATION_CHANNEL_DESCRIPTION"

3. 알림 채널의 진동 유무를 설정합니다. (Optional)

알림 채널의 값은 DFINERY 콘솔에서 설정 한 값 중 '앱 실행 중 푸시 메시지 노출'을 제외한 모든 설정보다 항상 우선시됩니다.

notificationChannel.enableVibration(true);
notificationChannel.enableVibration(true)

4. 알림 채널의 알림음을 설정합니다. (Optional)

시스템 기본 알림음을 재생하도록 설정한 예제입니다.

Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
        .build();
notificationChannel.setSound(soundUri, audioAttributes);
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val audioAttributes = AudioAttributes.Builder()
    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
    .build()
notificationChannel.setSound(soundUri, audioAttributes)

5. NotificationManager에 생성한 알림 채널을 등록합니다.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(notificationChannel)

6. 완료되었습니다.

Firebase 사용자 인증 정보 비공개 키 파일 발급 따라해보기

2. 발급 하고 싶은 키의 프로젝트를 선택합니다.

3. 우측 하단의 작업에서 ⋮를 클릭합니다.

4. 드롭다운에서 키 관리를 클릭합니다.

5. 키 추가를 선택합니다.

이미 생성된 키가 있을 경우, 기존에 키를 생성한 이력이 있다는 뜻이며 해당 키를 사용하시면 됩니다. 해당 키를 찾을 수 없을 경우 새로 키를 생성하여 주시기 바랍니다.

6. 드롭다운에서 새 키 만들기를 클릭합니다.

7. JSON을 선택 후 만들기를 클릭합니다.

8. 키 발급이 완료되었습니다.

발신자 ID 확인 방법

  1. 프로젝트를 선택합니다.

  2. 좌측 패널에서 프로젝트 개요 오른쪽 ⚙️ 아이콘을 클릭합니다.

  3. 프로젝트 설정을 클릭합니다.

  4. 프로젝트 설정 상단 탭에서 클라우드 메시징을 클릭합니다.

DFINERY는 푸시 알림을 작성하는데 를 필요로 하므로 다음의 일련의 단계를 완료하세요.

Firebase에서 제공되는 의 지시사항에 따라 Android 프로젝트에 Firebase를 추가합니다.

Firebase에서 제공되는 의 지시사항에 따라 다음의 항목을 적용합니다.

토큰은 자주 변경되지 않으므로 코드가 자주 불리지 않도록 Application을 상속받은 객체의 메소드에 작성하시는 것을 권장드립니다.

FirebaseMessagingService를 상속받은 클래스에서 메소드를 Override 하여 토큰을 DFINERY에 등록합니다.

Android 8.0부터는 알림을 수신받기 위해 알림 채널 생성이 필요합니다. Android에서 제공하는 의 지시사항과 를 참고하여 알림 채널을 생성해주시기 바랍니다.

푸시가 수신되면 FirebaseMessagingService를 상속받은 객체에 푸시 알림이 수신 됩니다. DFINERY는 수신된 푸시 페이로드를 토대로 알림을 생성하므로 해당 객체의 메소드 내에 다음과 같이 작성하여 주시기 바랍니다.

딥 링크 정보를 가지고 있는 푸시를 클릭하면 딥링크에 설정된 가 실행됩니다. 딥링크가 정보가 없을 경우 android.intent.action.MAIN 액션을 가지고 있는 Activity가 실행됩니다.

Activity에 딥 링크를 연동하는 방법은 Android에서 제공하는 를 참고하여 주시기 바랍니다.

알림 채널을 생성하는 예제입니다. 도 있으므로 참고 바랍니다.

알림 채널 API는 이상에서 지원합니다.

세번째 파라미터 importance는 이 알림 채널로 수신될 푸시 알림의 를 의미합니다.

1. 에 접속합니다.

프로젝트가 없을 경우 Firebase 프로젝트 생성이 되지 않았다는 뜻이므로 를 참고하여 Firebase 프로젝트를 생성합니다.

로 이동합니다.

를 확인합니다.

Support Library
Android 프로젝트에 Firebase 추가
Android에서 Firebase 클라우드 메시징 클라이언트 앱 설정
앱 매니페스트에 FirebaseMessagingService를 상속받는 서비스 추가
Android 13 이상에서 적용되는 런타임 알림 권한 요청 작성
기기 등록 토큰 액세스 연동
onCreate()
onNewToken(String)
onMessageReceived(RemoteMessage)
Activity
앱 콘텐츠 딥 링크 만들기
Android에서 제공하는 예제
Android 8.0
중요도
서비스 계정
Android 프로젝트에 Firebase 추가하기
Firebase Console
발신자 ID
알림 채널 만들기 및 관리
알림 채널 생성 따라해보기
정보통신망법
DFINERY 콘솔
발신자 ID 확인 방법
Firebase 사용자 인증 정보 비공개 키 파일 발급 방법
알림 수신 동의 설정하기
System Default Color
Userset Accent Color