Oracle Help Center | Oracle Responsys Mobile App Platform Cloud Service title

Notification Preferences

Notification Preferences allow your users to make choices about the kind of push notifications they want to receive. Rather than turning off notifications, users can choose ones they value. For example, a user may choose to receive notifications about score updates for his or her favorite sports team and opt out of other teams' updates.

Before you begin: Work with your marketing team to define which Notification Preferences to offer in your app, as described in the Design Mobile Apps for Responsys topic. First, decide on the grouping of the kinds of notifications that users may want to limit. These groups will become your Notification Preferences. For example, the preference for a favorite team may contain a concise name or abbreviation for that team. Another preference could denote whether a user wishes to receive news updates. A third preference could be used to inform when ticket sale prices have dropped to a specified threshold.

You may have as many as 30 preferences. Notification Preferences have 3 properties:

Declaration Field Validation Rules
Key Valid key names for preferences may only contain alphanumeric characters and underscores, and must be between 1 and 25 characters in length. Key names are case-sensitive. Use unique, uppercase names for the preference key names. Responsys treats the preference key names as all uppercase.
Label Human-readable labels for your application to display. All unicode characters are valid for these labels, but they must be between 1 and 1024 characters in length.
preferenceType BOOLEAN, STRING, or NUMBER. Coordinate with the Responsys Account Admin regarding preferenceType (BOOLEAN, STRING, or NUMBER), so that the Responsys Account Admin can set up the correct data mapping in Responsys for the preferences fields.

 

Coding the Notification Preferences

Once you have decided upon your Notification Preferences for your app, you'll first need to declare them and set default values for them using the PushIO SDK, per the sections below. Later, you'll want to create a user interface in your app to let the user modify their preferences.

DeclarePreference

Declare the preferences you wish to use at the start of each app session, because declared preferences are not stored persistently until values are set for them (as described in the next section).

    PushIOManager pushIOManager = PushIOManager.getInstance(this);
        try 
        {        
            pushIOManager.declarePreference("NEWS", "News", PushIOPreference.Type.BOOLEAN);  // (key, label, preferenceType)

            pushIOManager.declarePreference("FAVORITE_TEAM", "Favorite Team", PushIOPreference.Type.STRING);

            pushIOManager.declarePreference("PRICE_LIMIT", "Price Limit", PushIOPreference.Type.NUMBER);
        }
        catch(ValidationException ex)
        {
            // Handle exception
        }

SetPreference

After declaring Notification Preferences, you'll want to set values for these preferences. You might do this to set default preference values after the user's device is registered for the first time or when the user wishes to make changes to his or her preferences.

Declare the preferences before setting them, because setting preferences without declaring them first is ignored.

    PushIOManager pushIOManager = PushIOManager.getInstance(this);

    try 
    {
        pushIOManager.setPreference("NEWS", true);
        pushIOManager.setPreference("FAVORITE_TEAM", "Colorado Rapids");
        pushIOManager.setPreference("PRICE_LIMIT", 23.33);
    }
    catch(ValidationException ex)
    {
        // Handle exception
    }

NOTE: Each call to setPreference(...) initiates a registration request. Calling this method multiple times creates a network and memory overhead. To minimize the number of outgoing registration requests, we recommended that this method be called from a central location at either the start or the end of an app session, as appropriate.

GetPreference

Use this API to retrieve preferences that have been declared and/or set.

    PushIOManager pushIOManager = PushIOManager.getInstance(this);

    // Get single preference
    PushIOPreference newsPreference = pushIOManager.getPreference("NEWS");

GetPreferences

Use this API to get a list of all the Notification preferences that have previously been declared and/or set.

    PushIOManager pushIOManager = PushIOManager.getInstance(this);

    // Get all stored preferences
    List<PushIOPreference> allPreferences = pushIOManager.getPreferences();

ClearAllPreferences

Use this API to delete the Notification preferences that were declared and set earlier.

    PushIOManager pushIOManager = PushIOManager.getInstance();
    List<PushIOPreference> preferences = pushIOManager.clearAllPreferences();