1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] ontap on notificaiton didnt initiate onMessageOpenedApp Firebase Flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 4, 2024 às 06:42.

  1. Stack

    Stack Membro Participativo

    hi i used this $payload = [
    'message' => [
    'token' => $token,
    // 'notification' => [
    //'title' => 'hey chat'
    // ],
    'data' => [
    'title' => $notification['title'],
    'description' => $notification['body']['description'],
    'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
    'body' => json_encode($notification['body']),
    ],
    'android' => [
    'priority' => 'high',
    ],
    ],
    ];


    this is my api side code if i comment it

    // 'notification' => [
    //'title' => 'hey chat'
    // ],


    i have to comment it becuase i want to show a custom sound when get chat request so now removing it problem is notification tap is not working when app is in recentList background i dont need notificaiton i alrady have create a customsound notification

    Future<void> foregroundNotificatioCustomAuddio(RemoteMessage payload) async {
    final initializationSettingsDarwin = DarwinInitializationSettings(
    defaultPresentBadge: true,
    requestSoundPermission: true,
    requestBadgePermission: true,
    defaultPresentSound: false,
    onDidReceiveLocalNotification: (id, title, body, payload) async {
    return;
    },
    );

    log('payload is ${payload.data['title']}');
    log('payload description 1 ${payload.data['description']}');

    final android = const AndroidInitializationSettings('@mipmap/ic_launcher');
    final initialSetting = InitializationSettings(
    android: android, iOS: initializationSettingsDarwin);

    localNotifications.initialize(initialSetting,
    onDidReceiveNotificationResponse: (NotificationResponse response) {
    print('Notification tapped: ${response.payload}');
    if (response.payload != null) {
    onSelectNotification(response.payload!); // Navigate or handle payload
    }
    });
    final customSound = 'app_sound.wav';
    AndroidNotificationDetails androidDetails = const AndroidNotificationDetails(
    'channel_id_17',
    'channel.name',
    importance: Importance.max,
    icon: "@mipmap/ic_launcher",
    playSound: true,
    enableVibration: true,
    sound: RawResourceAndroidNotificationSound('app_sound'),
    );

    final iOSDetails = DarwinNotificationDetails(
    sound: customSound,
    );
    final platformChannelSpecifics =
    NotificationDetails(android: androidDetails, iOS: iOSDetails);
    global.sp = await SharedPreferences.getInstance();

    if (global.sp!.getString("currentUser") != null) {
    await localNotifications.show(
    10,
    payload.data['title'], //message.data["title"]
    payload.data['description'] ?? '',
    platformChannelSpecifics,
    payload: json.encode(payload.data.toString()),
    );
    }


    }

    Continue reading...

Compartilhe esta Página