Я пытаюсь получить дополнительный пакет, когда открываю приложение при нажатии на уведомление.
У меня есть этот метод на MainActivity:
private void getBundleFromFirebaseMessaging(){
Intent intent = this.getIntent();
if (intent != null && intent.getExtras() != null) {
Bundle b = getIntent().getExtras();
boolean cameFromNotification = b.getBoolean("fromNotification");
if (cameFromNotification) {
Toast.makeText(this, "FROM PUSH", Toast.LENGTH_SHORT).show();
}
}
Единственный пакет, который я получаю, это _fbSourceApplicationHasBeenSet.
Это мой метод в моем классе FirebaseMessaging
private fun sendNotification(message: RemoteMessage) {
val messageBody = message.notification?.body
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra("fromNotification", true)
val pendingIntent = PendingIntent.getActivity(this,
0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT)
val channelId = getString(R.string.notification_channel)
val channelName = getString(R.string.notification_channel_name)
val defaultSoundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat
.Builder(this, channelId)
.setSmallIcon(R.drawable.login_logo)
.setContentTitle("Title")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(channelId,
channelName,
NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
}
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
}