Android: Firebase Push Benachrichtigung Tiefe Links funktionieren nicht mit dem Kaltstart (funktioniert nur, wenn die ApAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Android: Firebase Push Benachrichtigung Tiefe Links funktionieren nicht mit dem Kaltstart (funktioniert nur, wenn die Ap

Post by Anonymous »

Ich habe ein Problem mit tiefen Links in meiner Android -App. Wenn ein Benutzer eine Push -Benachrichtigung mit einem Deep -Link erhält, funktioniert er perfekt, wenn die App bereits ausgeführt wird. Wenn die App jedoch vollständig geschlossen ist (nicht in den letzten Apps), öffnet das Klicken auf die Benachrichtigung die App, ignoriert jedoch den Deep -Link vollständig. Schema: appname: // chat/{chatid}/{userId}
Das Problem
Wenn App ausgeführt wird oder im Hintergrund: Deep -Link -Navigation funktioniert perfekt
Wenn App vollständig geschlossen ist: App eröffnet, aber Deep -Link wird ignoriert (keine Log -Brotes. Die tiefen Link wurde verarbeitet. />
[*] FireBase Messaging Service (AppFirebasemessAgingService.KT)
Kotlin < /p>
Überschreibung Spaß an. "Chat"
var DeepLink: String? = null
var notificationId = system.currentTimemillis (). toint () < /p>
if (remoteMessage.data.isNotEmpty()) {
title = remoteMessage.data["title"] ?: ""
message = remoteMessage.data["message"] ?: ""
category = remoteMessage.data["category"] ?: category
deepLink = remoteMessage.data["deepLink"]
// ...
}

// Show notification if we have content
if (title.isNotEmpty() || message.isNotEmpty()) {
showNotification(notificationId, title, message, category, deepLink)
}
< /code>
} < /p>
private Fun -ShowTification (
NotificationId: int,
Titel: String,
Nachricht: String,
Kategorie: String,
Deeplink: String? />Intent(Intent.action_view, Deeplink.touri ()). Anwenden {
package< /code> = packageName
addflags(Intent.flag_activity_clear_top)
}
} else {
Intent (this, mainActivity :: class.java) .Apply {
addflags(intentity.flag_Clear_toply_toply_toply_toply_toply />addflags(Intent.flag_activity_new_task)
}
} < /p>
Log.d("FCMService", "Creating notification with intent: $intent")
Log.d("FCMService", "Intent URI: ${intent.data}")

val pendingIntent = PendingIntent.getActivity(
this,
System.currentTimeMillis().toInt(),
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT
)

// Build notification
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)

val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(notificationId, notificationBuilder.build())
< /code>
}
2. MainActivity Deep Link Handling
KotlinOverride Fun OnCreate (SavedInstancestate: Bundle?) {
super.oncreate(savedInstancestate)
// Setup UI, etc...
setContent {
navController = rememberNavController()
AppAndroidTheme {
// Main content...
}
}

if (intent?.action == Intent.ACTION_VIEW) {
handleDeepLink(intent)
}
< /code>
} < /p>
Überschreiben Sie Spaß onNewintent (Absicht: Absicht) {
Super.onNewintent(Intent)
logintent ("onnewintent", Intent) < /p>

// Set the new intent
setIntent(intent)
navController.handleDeepLink(intent)

// Handle it if it's a deep link
if (intent.action == Intent.ACTION_VIEW) {
handleDeepLink(intent)
}
< /code>
} < /p>
private Fun Handleleplink (Intent: Intent) {
val uri = intent.data
log.d(tag, "Verarbeitung von Deep Link Uri: $ uri") < /p>
if (uri != null && uri.scheme == "appNAme") {
when (uri.host) {
"chat" -> {
// Extract path segments
val pathSegments = uri.pathSegments
Log.d(TAG, "Path segments: $pathSegments")

if (pathSegments.size >= 2) {
val chatId = pathSegments[0]
val userId = pathSegments[1]

Log.d(TAG, "Navigating to chat: chatId=$chatId, userId=$userId")

// Wait for UI to be ready before navigating
Handler(Looper.getMainLooper()).postDelayed({
navigateToChat(chatId, userId)
}, 300)
}
}
}
}
< /code>
} < /p>
private fun navigateToChat(chatId: String, userId: String) {
try {
Log.d(TAG, "Attempting navigation to chat screen with chatId=$chatId, userId=$userId")

navController.navigate(MainScreens.ChatScreen(chatId, userId)) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}

Log.d(TAG, "Navigation completed")
} catch (e: Exception) {
Log.e(TAG, "Navigation error", e)
}
}
< /code>
< /li>
Naviggraph Deep Link Konfiguration Kotlin < /p>
CompoSable (
DeepLinks = Listof (
navdeeplink(

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post