Android Dev/Navigation / / 2021. 6. 11. 01:00

Navigation Pending Intent with Deeplink ( Notification Builder) / And Get bundle

번들로 넘겨야함

 

val channelId = "123"
val textMsg = data["body"].toString()?:""
val title = data["title"]
val bundleExample = Bundle()
bundleExample.putString("targetNick" , data["title"] )
bundleExample.putString("targetFid" , data["targetFid"] )
bundleExample.putString("category" , notificationType )
bundleExample.putString("chatRoomId" , data["chatRoomId"] )
bundleExample.putString("picturePath" , data["picturePath"])



val pendingIntent: PendingIntent = NavDeepLinkBuilder(this)
.setGraph(R.navigation.nav_m1_graph)
.setDestination(R.id.m5_chat_inside)
.setComponentName(M1MainstreamRe::class.java)
.setArguments(bundleExample)
.createPendingIntent()

// val deeplink = findNavController().createDeepLink()
// .setDestination(R.id.m5_chat_inside)
// .setArguments(args)
// .createPendingIntent()

val notificationBuilder = NotificationCompat.Builder(this, channelId) //.setContentTitle(title)
.setGroup("GROUP1")
.setAutoCancel(true)
.setContentTitle(title)
.setSmallIcon(R.drawable.store_balloons_128)
.setContentText(textMsg)
// .setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_VIBRATE)
.setContentIntent(pendingIntent)
.build()

 

//ChannelName Setting해주어야한다
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
val channelName = "123"
val channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
}
else
{
Log.e("fcmchecker", "SDK 버전이 낮아 channel이 형성되지않음")
}

NotificationManagerCompat.from(this).
notify(data["targetFid"], 3, notificationBuilder)

 

 

 

받는쪽 

 

var partnerNickname = ""
if(requireArguments()["targetFid"] != "" && requireArguments()["targetFid"] != null)
{
partnerNickname = requireArguments()["targetNick"].toString()
partnerFid = requireArguments()["targetFid"].toString()
picturePath = requireArguments()["picturePath"].toString()
}
else
{
partnerNickname = args.partnerInfo.partnerNickname
partnerFid = args.partnerInfo.partnerFid
picturePath = args.partnerInfo.picturePath
}

'Android Dev > Navigation' 카테고리의 다른 글

Navigation Guide Links  (0) 2021.06.30
Fragment Procedure with Navigation + Databinding + Firebase 예제  (0) 2021.05.22
Navigation 정리  (0) 2021.05.22
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유