Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] : fcm 소리 추가 및 직접 부팅 모드 설정 #118

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dependencies {
implementation Dependencies.firebasektx
implementation Dependencies.firebasedynamiclink
implementation Dependencies.firebasemessaging
implementation Dependencies.firebaseMessagingDirectboot

implementation Dependencies.workermanager

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
</activity>
<service
android:name=".service.FairerFirebaseMessagingService"
android:exported="false">
android:exported="false"
android:directBootAware="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/java/com/depromeet/housekeeper/service/FCMWorker.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.app.PendingIntent
import android.app.PendingIntent.FLAG_ONE_SHOT
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
Expand All @@ -34,8 +35,9 @@ class FairerFirebaseMessagingService: FirebaseMessagingService() {
@Override
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
Timber.d("From: ${message.from}")
Timber.tag(TAG_FCM).d("From: ${message.from}")
if (message.data.isNotEmpty()) {

// payload : 전송된 데이터
Timber.tag(TAG_FCM).d("Message data payload: ${message.data}")

Expand All @@ -53,22 +55,24 @@ class FairerFirebaseMessagingService: FirebaseMessagingService() {
@SuppressLint("UnspecifiedImmutableFlag")
private fun showNotification(messageTitle: String?, messageBody: String?) {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val notificationID = Random.nextInt() // 고유 id를 지정
val notificationID = (System.currentTimeMillis() / 7).toInt() // 고유 ID 지정

createNotificationChannel(notificationManager)

val intent = Intent(this, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
val pendingIntent = PendingIntent.getActivity(this, notificationID, intent, FLAG_ONE_SHOT)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)

val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher_fairer)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setSound(soundUri) // 알림 소리
.setAutoCancel(true) // 알림 터치 시 자동으로 삭제
.setContentIntent(pendingIntent)
.build()

notificationManager.notify(notificationID, notificationBuilder)
Expand All @@ -85,27 +89,6 @@ class FairerFirebaseMessagingService: FirebaseMessagingService() {
notificationManager.createNotificationChannel(channel)
}

// TODO : WorkerManager 이용해서 FCM Managing
private fun sendFCMTokenToServer(context: Context) {
val constraints = Constraints.Builder()
/* 네트워크 연결상태 & 배터리 부족에 대한 제약 조건 */
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(true)
.build()

// 10, 20, 40초 늘려가며 retry
val workRequest = OneTimeWorkRequestBuilder<FCMWorker>()
.setConstraints(constraints)
.setBackoffCriteria(
BackoffPolicy.LINEAR,
OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS)
.build()

val workManager = WorkManager.getInstance(context)
workManager.enqueue(workRequest)
}

companion object {
private const val CHANNEL_NAME = "FairerNotification"
private const val CHANNEL_DESCRIPTION = "Channel For Fairer Notification"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.depromeet.housekeeper.ui

import android.app.Application
import android.content.Context
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import androidx.work.*
import com.depromeet.housekeeper.local.PrefsManager
import com.depromeet.housekeeper.model.SocialType
import com.depromeet.housekeeper.model.Token
import com.depromeet.housekeeper.network.remote.model.LoginResponse
import com.depromeet.housekeeper.network.remote.repository.Repository
import com.depromeet.housekeeper.service.FCMWorker
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.concurrent.TimeUnit

class LoginViewModel(application: Application) : AndroidViewModel(application) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ object Dependencies {

private const val FIREBASE_BOM = "30.0.2"
private const val FIREBASE_MESSAGING = "23.0.6"
private const val FIREBASE_MESSAGING_DIRECTBOOT = "20.2.0"
const val firebaseBOM = "com.google.firebase:firebase-bom:$FIREBASE_BOM"
const val firebasektx = "com.google.firebase:firebase-analytics-ktx"
const val firebasedynamiclink = "com.google.firebase:firebase-dynamic-links-ktx"
const val firebasemessaging = "com.google.firebase:firebase-messaging-ktx:$FIREBASE_MESSAGING"
const val firebaseMessagingDirectboot = "com.google.firebase:firebase-messaging-directboot:$FIREBASE_MESSAGING_DIRECTBOOT"

private const val GLIDE = "4.13.0"
const val glide ="com.github.bumptech.glide:glide:$GLIDE"
Expand Down