0
I am using firebase messaging version 9.0 and wish to redirect the user to a specific screen when receiving and click a notification when the app is closed.
I can currently redirect with the app open or minimized, but I didn’t understand how to do this when the app isn’t open.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
Model model = Model();
id = "sasassa;
Get.offNamed("$SCREEN_ROUTE",arguments: model);
Storage storage = Storage();
storage.setReceivedNotification(true);
print("teste notificação recebida");
}
FirebaseMessaging.instance.getInitialMessage().then((message){
if (message != null){
Model model = Model();
id = "sasassa;
Get.offNamed("$SCREEN_ROUTE",arguments: model);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("a");
storage.setReceivedNotification(true);
Model model = Model();
id = "sasassa;
Get.offNamed("$SCREEN_ROUTE",arguments: model);
//storage.setUserChallenged("60f23d0803c1fd000a03c36e");
//showMyDialog(corpo: message);
//Navigator.pushNamed(context, '/events');
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
print("b");
storage.setReceivedNotification(true);
print("teste b $message");
String? corpo = message.notification?.body;
String? titulo = message.notification?.title;
String? image = message.notification?.android?.imageUrl;
//showMyDialog(titulo: titulo,corpo: corpo);
print("$corpo $titulo $image");
});
Tentei usar shared preference no backgroundHandler, mas dessa maneira ocorrerá o redirecionamento mesmo sem o usuário clicar na notificação.
Alguém teria instruções de como realizar o redirecionamento a com o app fechado a partir do click numa notificiação específica?
PS: Sei que preciso mandar os dados no corpo da notificação, só quero entender como fazer o flutter capturar o click com o app fechado na versão 9.0 ou superior.
Search about Deep Link on Android and iOS, with this you will be able to do what you want.
– Matheus Ribeiro
Matheus Ribeiro, thank you for your comment. I’ve used Dynamic links to open the closed app from the click on links. My question more precisely would be about capturing the click notification with the app closed, being able to identify this event I can do what I want, really Deep Link has direct relation to perform this action in notifications?
– Lucas santos