-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: fcm lib 세팅 #9 * feat: FirebaseMessagaeService 추가 #9 * feat: 알림 권한 로직 추가 #9 * feat: app launch icon 추가 #16 * improve: lint format * chore: lint 통과용 파일 생성 * chore: fcm 설정에 따른 workflow 수정 * �chore: fix ci project name * del: app/google-services.json * improve : splash import 오류
- Loading branch information
Showing
26 changed files
with
926 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions
82
app/src/main/java/nexters/hyomk/dontforget/fcm/MyFirebaseMessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package nexters.hyomk.dontforget.fcm | ||
|
||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.media.RingtoneManager | ||
import android.os.Build | ||
import androidx.compose.ui.input.key.Key.Companion.J | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import nexters.hyomk.dontforget.MainActivity | ||
import nexters.hyomk.dontforget.R | ||
import timber.log.Timber | ||
|
||
class MyFirebaseMessageService : FirebaseMessagingService() { | ||
// 새로운 토큰이 생성될 때 마다 해당 콜백이 호출된다. | ||
override fun onNewToken(token: String) { | ||
super.onNewToken(token) | ||
Timber.d("onNewToken: $token") | ||
// TODO 새로운 토큰 수신 시 서버로 전송 | ||
// MainActivity.uploadToken(token) | ||
} | ||
|
||
// Foreground에서 Push Service를 받기 위해 Notification 설정 | ||
override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
J | ||
Timber.d("From: ${remoteMessage.from}") | ||
|
||
// Check if message contains a data payload. | ||
if (remoteMessage.data.isNotEmpty()) { | ||
Timber.d("Message data payload: ${remoteMessage.data}") | ||
|
||
// Check if data needs to be processed by long running job | ||
} | ||
|
||
// Check if message contains a notification payload. | ||
remoteMessage.notification?.let { | ||
Timber.d("Message Notification Body: ${it.body}") | ||
sendNotification(it.title ?: getString(R.string.default_notification_channel_id), it.body ?: "") | ||
} | ||
} | ||
|
||
private fun sendNotification(title: String, body: String) { | ||
val notifyId = (System.currentTimeMillis() / 7).toInt() | ||
Timber.d("get noti$title / $body") | ||
|
||
val intent = Intent(this, MainActivity::class.java) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | ||
val pendingIntent = | ||
PendingIntent.getActivity(this, notifyId, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE) | ||
|
||
val channelId = getString(R.string.default_notification_channel_id) | ||
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | ||
|
||
val notificationBuilder = NotificationCompat.Builder(this, channelId) | ||
.setSmallIcon(R.drawable.ic_app) | ||
.setContentTitle(title) | ||
.setContentText(body) | ||
.setPriority(NotificationManagerCompat.IMPORTANCE_HIGH) | ||
.setAutoCancel(true) | ||
.setSound(soundUri) | ||
.setContentIntent(pendingIntent) | ||
|
||
val notificationManager = | ||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val channel = NotificationChannel( | ||
channelId, | ||
channelId, | ||
NotificationManager.IMPORTANCE_HIGH, | ||
) | ||
notificationManager.createNotificationChannel(channel) | ||
} | ||
|
||
notificationManager.notify(notifyId, notificationBuilder.build()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.