Android Heads Up Firebase Notification не работает - PullRequest
1 голос
/ 12 апреля 2020

Я застрял в этой, казалось бы, простой проблеме уже 4 дня. Я хочу, чтобы мои уведомления в Android выглядели как баннер, как они делают в iOS, они называются Heads Up-уведомлениями, как мне сказали. После просмотра многих постов у меня сложилось впечатление, что мне нужно только установить высокий приоритет и включить звук.

Однако я не могу сделать ни одного из них даже с консоли FCM и ни с моего laravel бэкэнд, для которого я использую Kreit.

Уведомления работают и достигают устройства, так как я сначала проверяю их с помощью firebase. Я получаю уведомления, НО они являются дискретными, и звук действительно происходит, НО без баннера.

Я прочитал какой-то пост, в котором говорится, что вам нужно повозиться с файлом манифеста и сделать что-то со стороной android , Я совершенно растерялся.

Вот весь мой полезный груз на laravel, который работает нормально, но не в хедс-апе.


        $deviceToken = 'chcC_kgZHrI0VpqpdPClE8XGJzwWV';
        // $name = 'Notification name'; //FIX_THIS_SOON figure this out soon
        $topic = 'Notification topic'; //FIX_THIS_SOON figure this out soon
        $condition = 'Notification condition'; //FIX_THIS_SOON figure this out soon
        $notificationTitle = 'Package is being delivered';
        // $notificationBody = 'Your order 9847GH8409 is on it\'s way to you.'; //version 1
        // $notificationBody = 'Your order 9847GH8419 is on it\'s way to you.'; //version 2
        $notificationBody = 'Your order 9847GH8429 is on its way to you.'; //version 3
        $notificationIcon = 'http://lorempixel.com/400/200/'; //
        $notificationImageUrl = 'http://lorempixel.com/400/200/';
        $notificationPriority = 'high';
        $apnsPayloadBadge = 42; //FIX_THIS_SOON
        $analyticsLabel = 'some-analytics-label'; //FIX_THIS_SOON

        // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
        $notificationPayload = [
            'title' => $notificationTitle,
            'body' => $notificationBody,
            //'image' => $notificationImageUrl,
        ];

        //payload needs to be configured from the parent function as an array, don't pass individual elements
        $data = [
            'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
            'action' => 'new_notification',
            'priority' => 'high', //does this need to be here?
            'sound' => 'default', //does this need to be here?
            'notification_id' => '888888888',
            'notification_uid' => '1111-2222-3333-4444',
            'notification_foreignUID' => '5555-6666-7777-8888',
            'notification_foreignUID_type' => 'user',
            'notification_title' => $notificationTitle,
            'notification_message' => $notificationBody,
            'notification_asset_type' => 'image',
            'notification_image' => 'http://127cf52a.ngrok.io/storage/images_products/860a6ac4-bd66-4c3b-b07f-450f7cdcc007_2020-01-20_15-15-21_0001.jpg',
            'notification_icon' => null,
            'notification_account_type' => 'client',
            'notification_read_status' => '0',
            'notification_status' => 'active',
            'notification_created_at' => '2020-03-29 02:09:00',
            'notification_updated_at' => '2020-03-29 02:09:00',
        ];

        $androidTtl = '3600s';

        $androidCollapseKey = '';

        $androidRestrictedPackageName = '';

        $androidNotificationPayload = [
            'title' => $notificationTitle,
            'body' => $notificationBody,
            // 'icon' => 'string',
            // 'color' => 'string',
            'sound' => 'default',
            // 'tag' => 'string',
            'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
            // 'body_loc_key' => 'string',
            /* 'body_loc_args' => [
                'string'
            ], */
            // 'title_loc_key' => 'string',
            /* 'title_loc_args' => [
                'string'
            ], */
            'channel_id' => 'Notifications',
            // 'ticker' => 'string',
            'sticky' => false, //When set to false or unset, the notification is automatically dismissed when the user clicks it in the panel. When set to true, the notification persists even when the user clicks it.
            // 'event_time' => 'string',
            'local_only' => true,
            'notification_priority' => 'priority_high', //also priority_max
            'default_sound' => true,
            'default_vibrate_timings' => true,
            'default_light_settings' => true,
            /* 'vibrate_timings' => [
                'string'
            ], */
            // 'visibility' => 'private',
            // 'notification_count' => integer,
            /* 'light_settings' => {
                "color" => {
                    object (Color)
                },
                "light_on_duration": string,
                "light_off_duration": string
            }, */ //i can't get to write the object properly
            // 'image' => $notificationImageUrl
        ];

        $androidFcmOptions = [
            'analytics_label' => $analyticsLabel //optional
        ];

        $webPushHeaders = [
            'Urgency' => 'high',
        ];

        $webPushFcmOptions = [
            // 'link' => '',
            'analytics_label' => $analyticsLabel //optional
        ];

        $apnsHeaders = [
            'apns-priority' => '10',
        ];

        $apnsPayload = [
            'aps' => [
                'alert' => [
                    'title' => $notificationTitle,
                    'body' => $notificationBody,
                ],
                'badge' => $apnsPayloadBadge,
            ],
        ];

        $apnsFcmOptions = [
            // 'image' => '',
            'analytics_label' => $analyticsLabel //optional
        ];

        // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidconfig
        $androidSettings = [
            'ttl' => $androidTtl,
            'priority' => $notificationPriority,
            // 'collapse_key' => $androidCollapseKey,
            // 'restricted_package_name' => $androidRestrictedPackageName,
            'notification' => $androidNotificationPayload,
            'data' => $data,
            'fcm_options' => $androidFcmOptions,
        ];

        // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig
        $apnsSettings = [
            'headers' => $apnsHeaders,
            'payload' => $apnsPayload,
            'fcm_options' => $apnsFcmOptions,
        ];

        // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig
        $webpushSettings = [
            'headers' => $webPushHeaders,
            'notification' => $androidNotificationPayload,
            'data' => $data,
            'fcm_options' => $webPushFcmOptions,
        ];

        //hide fcm_options if you are leaving it empty
        // https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#fcmoptions
        $fcmOptions = [
            'analytics_label' => $analyticsLabel //optional
        ];

        //DELETE_SOON
        Log::channel('merlin_debug')->info('option 3 222');

        $message = new RawMessageFromArray([
            'token' => $deviceToken,
            // 'name' => $name,
            // 'topic' => $topic,
            // 'condition' => $condition,
            'notification' => $notificationPayload,
            'data' => $data,
            'android' => $androidSettings,
            'apns' => $apnsSettings,
            'webpush' => $webpushSettings,
            'fcm_options' => $fcmOptions
        ]);

        $messaging = app('firebase.messaging');

        $messaging->send($message);

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...