Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich Push Notification #2208

Closed
diamondobama opened this issue Sep 5, 2017 · 4 comments
Closed

Rich Push Notification #2208

diamondobama opened this issue Sep 5, 2017 · 4 comments
Assignees
Milestone

Comments

@diamondobama
Copy link
Contributor

diamondobama commented Sep 5, 2017

Codename One should support high-level customization of push notification on iOS and Android. Currently, the only push that could be sent is basic.

Some of the features that can be added are:

  • Adding custom action buttons to notifications other than the default Open button, e.g. Reply and Save for Later buttons.
  • Writing and posting text from within notification, like iMessage Reply.
  • Adding an image to a notification.
  • Showing a different text when a notification is expanded.
  • Adding a frame to push content.

Examples of some of these features can be found below:

asset 1
asset 2
asset 3
asset 4
asset 5
asset 6

@codenameone codenameone self-assigned this Sep 5, 2017
@codenameone codenameone added this to the Version 3.9 milestone Sep 5, 2017
@codenameone codenameone modified the milestones: Version 4.0, Version 5.0 Feb 21, 2018
@codenameone codenameone assigned shannah and unassigned codenameone Feb 21, 2018
@codenameone
Copy link
Collaborator

I'd like to address these but all of my issues are going to 5.0 right now so I'm pushing back all RFE's.

@shannah
Copy link
Collaborator

shannah commented Jul 11, 2018

Custom actions and image attachments have been added. See
https://github.com/codenameone/CodenameOne/wiki/Push-Notifications

I have not added:

  1. support for text input inside push notifications (e.g. reply) - This can be implemented on iOS and Android fairly easily... and I still plan to do this.
  2. Different text when expanded. - This is trickier, as the examples that you posted are implemented using a custom UIView from the app extension - and there are major limitations on what you can do in this context - e.g. we can't just show a Codename One view. I have a few ideas on how we can achieve something in this space, but I'll need to experiment.

I don't know what "Adding a frame to push content." is referring to.

NOTE: Image attachment support requires an additional provisioning profile to be generated. The certificate wizard will generate this automatically and make it available to the build server during builds - but you'll need to generate new provisioning profiles for your app (using the certificate wizard) to trigger this.

@shannah
Copy link
Collaborator

shannah commented Aug 23, 2018

Status update: Test input is implemented in iOS, but not in Android yet. I have run into some difficulty getting android to work properly. Will take another shot at it soon.

I don't think I'm going to include the "Different text when expanded" in this RFE. It may be best handled natively.

@codenameone codenameone modified the milestones: Version 5.0, Version 6.0 Sep 21, 2018
shannah added a commit that referenced this issue Jan 31, 2019
@shannah
Copy link
Collaborator

shannah commented Jan 31, 2019

I have finally added support for text replies as part of a push notification on Android. This completes this issue.

Example usage.

The app main class should implement PushActionProvider. It will define a method that returns a set of categories. E.g.

@Override
    public PushActionCategory[] getPushActionCategories() {
        return new PushActionCategory[]{
            new PushActionCategory("fo", new PushAction[]{
                new PushAction("yes", "Yes"),
                new PushAction("no", "No"),
                new PushAction("maybe", "Maybe", null, "Enter reason", "Reply")
            })
            
        };
    }

Then, when sending a push notification, you can specify the "category" of the message. If the category corresponds with a defined category in your getPushActionCategories() method, then the user will be presented with a set of buttons corresponding to the PushActions in that category.

In the above example, we would send a push type 99 and a body of

<push type="0" body="Hello" category="fo"/>

This would trigger the "fo" category that we defined, which has 3 actions: Yes, No, and Maybe. And the "Maybe" action will provide a text input because of the extra parameters provided:

new PushAction("maybe", "Maybe", null, "Enter reason", "Reply")

The last 2 parameters are the "hint" text and the reply button label. On android, the notification will look like

image

If you click on "Maybe" (with API 27 or higher), then you'll get a text field to enter a reply directly.

You can retrieve both which action was pressed, and what the user text input was using the PushContent class.

An example push callback method to retrieve this data:

@Override
    public void push(String value) {
        PushContent data = PushContent.get();
        if (data != null) {
            System.out.println("Image URL: "+data.getImageUrl());
            System.out.println("Category: "+data.getCategory());
            System.out.println("Action: "+data.getActionId());
            System.out.println("Text Response: "+data.getTextResponse());
        } else {
            System.out.println("PushContent is null");
        }
        System.out.println("Push "+value);
        Display.getInstance().callSerially(()->{
            Dialog.show("Push received", value, "OK", null);
        });
    }

@shannah shannah closed this as completed Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants