728x90

last Update : 2019.8.30


Firebase 클라우드 메시징(FCM)은 메시지를 무료로 안정적으로 전송할 수 있는 교차 플랫폼 메시징 솔루션이다.

구글이 PUSH 메시징 플랫폼을 GCM(Google Cloud Message) 에서 FCM(Firebase Cloud Message) 로 변경을 권고하면서 구글에서 GCM 메시지 전송을 위한 설정 세팅 정보 연결을 찾기가 어렵다. (2017.4.11 기준)

안드로이드 9.0 부터는 GCM 은 동작하지 않는다.


FCM(Firebase Cloud Message) 를 활용하여 PUSH 알림 메시지를 구현하고자 한다.

- 공지 전송 전용 게시판에 글을 등록하여 지정된 회원에게 PUSH 메시지 전송

- 서버 게시판에서 특정 글을 등록하면 지정된 회원에게 PUSH 메시지 자동 전송



https://firebase.google.com/docs/cloud-messaging/ 에 동영상으로 설명이 나오고, 주요기능 및 작동원리, 구현경로에 대한 설명이 잘되어 있다.


가장 먼저 해야 할 일은 구글 계정에서 FCM 등록을 하는 법이다.


1. https://console.firebase.google.com/ 에 접속한다.

   프로젝트를 추가한다.  




안드로이드 앱의 패키지명을 입력한다.


위 그림에서 잘 보면 파일의 위치가 해당 앱 폴더 아래에 위치한다.

해당 앱 모듈의 build.gradle 이 있는 폴더에 google-services.json 파일을 넣어주어야 한다.



모듈 앱에 빠진 부분을 추가한다.

https://firebase.google.com/docs/android/setup 에 가면 가장 최신 Firebase 라이브러리 파일 정보가 나온다.


프로젝트 수준 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
   
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.2.0'       
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


앱 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion = '28.0.3'

    defaultConfig {
        applicationId "com.link2me.android.contact"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'gun0912.ted:tedpermission:2.0.0'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.github.bumptech.glide:glide:3.8.0' // 이미지 라이브러리
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'

}

apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin


gradle.properties

android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx1536m


These two lines automatically resolved my dependency conflicts between google's files and third party dependencies.

두 줄을 추가하면 구글 파일과 서드파티 dependencies 사이의 충돌이 나서 빨간 줄 표시나는 걸 해결해준다.


이제 안드로이드 앱에서 구현할 소스와 PHP(Web) 소스를 구현하면 된다.

블로그 이미지

Link2Me

,