android6-8 Exercise 3: Messaging service and Data safety ===================================================== import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage class NotesMessagingService : FirebaseMessagingService() { // Docs: called for data messages, and for notification messages while the app is in the foreground; // runs on a background thread; finish within about 20 seconds override fun onMessageReceived(message: RemoteMessage) { val text = message.data["text"] ?: message.notification?.body ?: return showReminder(applicationContext, noteId = 0L, text = text) // Chapter 4's function } // Docs: called when a token is first generated and when it changes. // The reference page marks onNewToken deprecated in favour of onRegistered: check the current guide. override fun onNewToken(token: String) { // send the token to YOUR server so it can address this device (never log it in release builds) } } // Manifest: register the service with the MESSAGING_EVENT intent filter (general knowledge; follow the guide) // Android 13+: showing a notification still needs POST_NOTIFICATIONS: Chapter 4's permission flow applies. Steps: register the service in the manifest following the current guide (the intent filter is general knowledge, not checked); send a console test message to the device with the app in the foreground, then in the background, and with a data-only message if the console allows. Report which callbacks ran (onMessageReceived? only the system tray?). The docs' background table was from the Unity guide, so confirm on the Android page. Then check the guide on onNewToken against onRegistered and update the code. Finally update your Chapter 7 Data safety answers for Crashlytics, Analytics, Remote Config and Messaging, using each product's own data-collection page (not read here). Code unrun.