Skip to content

Commit

Permalink
feat: FCM 딥링크 호출 대응
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Feb 10, 2024
1 parent 45e4d6e commit bed1155
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/no5ing/bbibbi/FirebaseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class FirebaseService : FirebaseMessagingService() {
remoteMessage.notification?.apply {
val intent = Intent(this@FirebaseService, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
remoteMessage.data.forEach { (t, u) ->
Timber.d("Extra data: $t, $u")
putExtra(t, u)
}
}
val pendingIntent = PendingIntent
.getActivity(this@FirebaseService, 0, intent, PendingIntent.FLAG_IMMUTABLE)
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/com/no5ing/bbibbi/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,31 @@ class MainActivity : ComponentActivity() {
private val deepLinkStateFlow = MutableStateFlow<String?>(null)
private val pendingDeepLinkDestination = MutableStateFlow<String?>(null)

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
override fun onNewIntent(newIntent: Intent?) {
super.onNewIntent(newIntent)
//HANDLE FOREGROUND INTENT (already app is active)
Timber.d("onNewIntent: $intent")
onAppStartIntent(intent)
intent = newIntent
Timber.d("onNewIntent: $newIntent")
onAppStartIntent(newIntent)
}

private fun onAppStartIntent(intent: Intent?) {
Timber.d("onAppStartIntent: $intent")
val appLinkData: Uri? = intent?.data
private fun onAppStartIntent(newIntent: Intent?) {
Timber.d("onAppStartIntent: $newIntent")
val appLinkData: Uri? = newIntent?.data
val deepLink = newIntent?.extras?.getString("aosDeepLink")
Timber.d("DeepLink: $deepLink")
val linkId = appLinkData?.let {
deepLinkStateFlow.value = it.toString()
getLinkIdFromUrl(it.toString())
}
if (linkId != null) {
handleDeepLinkId(linkId)
}
deepLink?.let {
pendingDeepLinkDestination.value = it
}

val widgetExtraData = intent?.extras?.getString(WIDGET_DEEPLINK_KEY) ?: return
val widgetExtraData = newIntent?.extras?.getString(WIDGET_DEEPLINK_KEY) ?: return
pendingDeepLinkDestination.value = widgetExtraData
}

Expand Down

0 comments on commit bed1155

Please sign in to comment.