Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Android] Add data/background message support#876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
anatoly-spb wants to merge4 commits intoOneSignal:main
base:main
Choose a base branch
Loading
fromanatoly-spb:add-remote-notification-handler

Conversation

anatoly-spb
Copy link

@anatoly-spbanatoly-spb commentedApr 5, 2023
edited
Loading

Description

One Line Summary

[Android] Add data/background message support

Details

Motivation

Since onesignal-cordova-plugin@3 we have no possibility to send data message without showing popup like a:

{  "app_id": "xxxx",  "include_player_ids": ["yyyy"],  "data": {     "action": "visit_refresh"  },  "content_available": true}

To process data message with content_available=true on Android I propose to add OSRemoteNotificationReceivedHandler
according tohttps://documentation.onesignal.com/docs/data-notifications#android-data-notification-setup
https://documentation.onesignal.com/docs/service-extensions#android-notification-service-extension

And notify about data/background message via setNotificationWillShowInForegroundHandler. So client API is not changed.

See
#835
#865
#875

Scope

Android

OPTIONAL - Other

Testing

Unit testing

Manual testing

I subscribe on setNotificationWillShowInForegroundHandler() in application:

            OneSignal.setNotificationWillShowInForegroundHandler((notificationReceivedEvent)=>{              const notification = notificationReceivedEvent.getNotification();              this.logger.log(`PushService: notificationWillShowInForeground: notification=${JSON.stringify(notification)}`);              // Silence notification by calling complete() with no argument              notificationReceivedEvent.complete(notification);            })

Run one on Android emulator from Android 7 to Android 12.

Send to application data message:

{  "app_id": "xxxx",  "include_player_ids": ["yyyy"],  "data": {     "action": "visit_refresh"  },  "content_available": true}

And I see in a log the following:

PushService: notificationWillShowInForeground: notification={"notificationId":"b62ab6da-7b24-46b2-8635-550b8d3cdbbe","additionalData":{"action":"visit_refresh"},"rawPayload":{"google.delivered_priority":"normal","google.sent_time":1680680487811,"google.ttl":259200,"google.original_priority":"normal","custom":"{\"a\":{\"action\":\"visit_refresh\"},\"i\":\"b62ab6da-7b24-46b2-8635-550b8d3cdbbe\"}","from":"267986468402","google.message_id":"0:1680680487816734%24bd0d61f9fd7ecd","google.c.sender.id":"267986468402"},"priority":0,"fromProjectNumber":"267986468402","lockScreenVisibility":1,"androidNotificationId":326831907}

We get data message notification as expected.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries

Checklist

Overview

  • I have filled out allREQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@marshall86
Copy link

I'm trying this fix and it seems to be working! Any idea how to do the same thing on iOS please? Many thanks

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jkasten2jkasten2Awaiting requested review from jkasten2

@nan-linan-liAwaiting requested review from nan-li

@emawbyemawbyAwaiting requested review from emawby

@jennantillajennantillaAwaiting requested review from jennantilla

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@anatoly-spb@marshall86

[8]ページ先頭

©2009-2025 Movatter.jp