Page 314 - 2020학년도 MDP과제발표회 자료집 (통신과) (3)
P. 314
Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ Ⅵ 안드로이드 어플리케이션
Ⅵ
o 파이어베이스 푸시 알림(FCM) 받아오기
package com.example.fb_slide;
import...
public class FireBaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
private String title="";
private String body="";
private String link="";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// 푸시울렸을때 화면깨우기.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE );
assert pm != null;
@SuppressLint("InvalidWakeLockTag")
PowerManager.WakeLock wakeLock =
pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG" );
wakeLock.acquire(3000);
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
title = remoteMessage.getData().get("title");
body = remoteMessage.getData().get("body");
link = remoteMessage.getData().get("link");
if (true) {
scheduleJob();
} else {
handleNow();
}
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " +
remoteMessage.getNotification().getBody());
Log.d(TAG, "Message Notification Body: " +
remoteMessage.getNotification().getTitle());
}
sendNotification();
}
- 326 -