Overview

In Acoustic Campaign, marketers can enhance their mobile app messages by adding actions. They can guide their customers to a certain path by asking them to complete a certain action. The actions added to the messages are defined by developers in the Acoustic Campaign UI. The type of action defined in the UI is mapped to plugins in the app or to the base Campaign SDK. The SDK then initiates the action based on the type received in a notification, and the customer is directed to the respective path.

Types of actions

Acoustic Campaign provides several built-in actions and plugins for additional custom actions. You can also customize the provided plugins to add actions or write your own custom action plugins.

Standard actions

The Standard actions are provided by Acoustic and are built-in the Campaign product. They are available in the UI for developers to create these actions. The following are the Standard actions provided:

  • Open app
  • Open dialer
  • Open URL
  • Show in-box notification {link to in-box topic when complete}

Acoustic Campaign also provides plugins for additional custom actions. Install the plugins and register the actions. You can also Register an action through a JSON file.

๐Ÿ“˜

Tip

For Android, registering the action through JSON is preferred.

๐Ÿ“˜

Note ( iOS only)

When you use the 'MceNotificationActionRegistry.registerNotificationAction' method to register a notification action, the registered callback function is called whether the app is running in the foreground or the background. After the app is terminated, the method is not called for the action provided. To enable the app to react to notification action when the app is not running, use the JSON configuration file method.

Snooze action plugin

The Snooze plugin allows a user to bring back the mobile app message after some time. This action removes the notification from the notification bar and restores it after a number of minutes.

๐Ÿ“˜

Tip

You should not have a single action as Snooze.

To send snooze action, you need to send the following action payload.

{
"type": "snooze", 
"time": "<the snooze time in minutes>"
}

Install the snooze plugin

The following example shows how to implement the plugins in your AppDelegate init method for iOS:


-(instancetype)init { if(self = [super init]) { [SnoozeActionPlugin registerPlugin]; } return self; }

  1. Extract and add the acoustic-mobile-push-android-sdk-plugin-snooze-<version number>.zip file from the plugins folder in the SDK package to your project as an Android library.
  2. Register the action with a type name. The following example uses the snooze type name.
    
    
    import co.acoustic.mobile.push.sdk.api.notification.MceNotificationActionRegistry; import co.acoustic.mobile.push.sdk.plugin.snooze.SnoozeAction; MceNotificationActionRegistry.registerNotificationAction("snooze", new SnoozeAction());
  3. Add the snooze intent service to the AndroidManifest.xml file.
    
    
    <service android:name="co.acoustic.mobile.push.sdk.plugin.snooze.SnoozeIntentService" />

To install the snooze plugin, run the following command


npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-snooze

To install the snooze plugin, run the following command:


cordova plugin add <path to downloaded directory>/plugins/co.acoustic.mobile.push.plugin.snooze cordova prepare

  1. To install the plugin, add these lines to your application's .csproj:
    
    
    <Compile Include="..\..\..\plugins\Actions\Snooze\SnoozeAction.Forms.cs"> <Link>Plugins\Action Plugins\SnoozeAction.Forms.cs</Link> <Folder Include="Plugins\Action Plugins\Snooze Action\" />
  2. As well as
    
    
    <Folder Include="Plugins\Action Plugins\Snooze Action\" />
  3. In the App.xaml.cs file, add a line to register the action:
    
    
    SDK.Instance.RegisterAction("snooze", new SnoozeAction())
  4. Add the associated Snooze plugin files to your application.

The snooze data is implemented when the page is initialized.

  1. Add the snooze plug-in to the pubspec.yaml file under dependencies.
flutter_acoustic_mobile_push_snooze: path: ../../plugins/flutter_acoustic_mobile_push_snooze
  1. Go to the SDK zip file and open the plugins folder. Then go to the snooze plugin folder and open the libs folder. From the libs folder, copy the flutter_acoustic_mobile_push_snooze.dart file into your applications libs folder.
  2. Import the snooze plug-in into the dart file.
import 'package:flutter_acoustic_mobile_push_snooze/flutter_acoustic_mobile_push_snooze.dart';

You can now reference the methods within the snooze.dart file.

Display web action plugin

The web action plugin allows a mobile app user to view a web page inside the app.
To send a web action, you need to send the following action payload.

{
"value": "<url>",// Url of web page to show (https only)
"type": "displayWebView"// Constant
}

Install the web action plugin

Web Action requires the following files in the plugins/web-action folder: WebActionPlugin.h, WebActionPlugin.m, WebViewController.h, and WebViewController.m. Then, register it in the AppDelegate.

The following example shows how to implement the plugins in your AppDelegate init method for iOS:


-(instancetype)init { if(self = [super init]) { [WebActionPlugin registerPlugin]; } return self; }

  1. Extract and add the acoustic-mobile-push-android-sdk-plugin-displayweb-<version number>.zip file from the plugins folder in the SDK package to your project as an Android library.
  2. Copy the resources that are located under res/layout, res/menu, and res/drawable (all the drawable folders) to your project.
  3. Add the strings action_back, action_forward, and action_done from the res/values/strings.xml file to your projectโ€™s strings.xml file.
  4. Add acoustic-mobile-push-android-sdk-plugin-displayweb-<version number>.jar file from the plugins folder in the SDK package to your project as an Android library.
  5. Register the action with a displayweb type name.
    
    
    import co.acoustic.mobile.push.sdk.api.notification.MceNotificationActionRegistry; import co.acoustic.mobile.push.sdk.plugin.displayweb.DisplayWebViewAction; MceNotificationActionRegistry.registerNotificationAction("displayWebView", new DisplayWebviewAction());
  6. Add the DisplayWeb activity to the AndroidManifest.xml file.
    
    
    <activity android:name="co.acoustic.mobile.push.plugins.DisplayWebViewActivity" </activity>

To install the plugin, run the following command:


npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-displayweb

To install the plugin, run the following command:


cordova plugin add &alt;path to downloaded directory&alt;/plugins/co.acoustic.mobile.push.plugin.displayweb cordova prepare

  1. Add these lines to your application's .csproj:
    
    
    <Compile Include="..\..\..\plugins\Actions\DisplayWeb\DisplayWeb.Forms.cs"> <Link>Plugins\Action Plugins\DisplayWeb.Forms.cs</Link> </Compile>
  2. As well as:
    
    
    <Folder Include="Plugins\Action Plugins\DisplayWeb Action\" />
  3. In the App.xaml.cs file, add these lines to register the action:
    
    
    // iOS and Android use different names for this plugin var displayWebAction = new WebViewAction(); SDK.Instance.RegisterAction("displayWebView", displayWebAction); SDK.Instance.RegisterAction("displayweb", displayWebAction);
  4. Add the associated DisplayWeb plugin files that ship with the SDK.

The web data is implemented when the page is initialized.

  1. Add the web action (displayweb) plug-in to the pubspec.yaml file under dependencies.
flutter_acoustic_mobile_push_displayweb: path: ../../plugins/flutter_acoustic_mobile_push_displayweb
  1. Go to the SDK zip file and open the plugins folder. Then go to the web action plugin folder and open the libs folder. From the libs folder, copy the flutter_acoustic_mobile_push_displayweb.dart file into your applications lib folder.
  2. Import the web action plug-in into the dart file.
import 'package:flutter_acoustic_mobile_push_displayweb/flutter_acoustic_mobile_push_displayweb.dart';

You can now reference the methods within the displayweb.dart file.

Add to calendar action plugin

The Add to calendar plugin allows a user to add an event to the calendar. This action happens in the background without opening the calendar. The following parameters are defined in the UI and sent to the device.

{
"interactive": true/false,// true = brings up interface to add event
"title": "<event title>", // text
"timeZone": "<timezone>", // text (optional)
"startDate": "<the event start datetime>", // formatted like 2015-04-07T10:10:10Z
"endDate": "<the event and datetime>", // formatted like 2015-04-07T10:10:10Z
"description": "<event notes>", // text (saved to notes)
"type": "calendar" // constant
}

If the time or timezone fields are incorrect, the timezone of the device is used. You can show the calendar user interface for adding an item to the calendar by adding interactive = true or false in the payload. If false, it does it in the background.

Install the Add to calendar plugin

Calendar requires AddToCalendarPlugin.h and AddToCalendarPlugin.m. For iOS 10 applications, add a description to NSCalendarsUsageDescription in the info.plist file that provides a reason to the user for allowing the app to add the calendar event.

The following example shows how to implement the plugins in your AppDelegate init method for iOS:


-(instancetype)init { if(self = [super init]) { [AddToCalendarPlugin registerPlugin]; } return self; }

  1. Extract and add the acoustic-mobile-push-android-sdk-plugin-calendar-<version number>.zip file from the plugins folder in the SDK package to your project as an Android library.
  2. Register the action with a calendar type name.
    
    
    import co.acoustic.mobile.push.sdk.api.notification.MceNotificationActionRegistry; import co.acoustic.mobile.push.sdk.plugin.calendar.AddToCalendarAction; MceNotificationActionRegistry.registerNotificationAction("calendar", new AddToCalendarAction());

To install the plugin, run the following command:


npm install --save <sdk folder>/plugins/react-native-acoustic-mobile-push-calendar

To install the plugin, run the following command:


cordova plugin add &alt;path to downloaded directory&alt;/plugins/co.acoustic.mobile.push.plugin.calendar cordova prepare

  1. In your application's .csproj file, add the resources:
    
    
    <Compile Include="..\..\..\plugins\Actions\Calendar\CalendarAction.Forms.cs"> <Link>Plugins\Action Plugins\CalendarAction.Forms.cs</Link> </Compile>
  2. As well as:
    
    
    <Folder Include="Plugins\Action Plugins\Calendar Action\" />
  3. In the App.xaml.cs file, add these lines to register the action:
    
    
    SDK.Instance.RegisterAction("calendar", new CalendarAction());
  4. Add the associated Calendar plugin files that ship with the SDK.

The calendar data is implemented when the page is initialized.

  1. Add the calendar plug-in to the pubspec.yaml file under dependencies.
flutter_acoustic_mobile_push_calendar: path: ../../plugins/flutter_acoustic_mobile_push_calendar
  1. Go to the SDK zip file and open the plugins folder. Then go to the calendar plugin folder and open the libs folder. From the libs folder, copy the flutter_acoustic_mobile_push_calendar.dart file into your applications lib folder.
  2. Import the calendar plug-in into the dart file.
import 'package:flutter_acoustic_mobile_push_calendar/flutter_acoustic_mobile_push_calendar.dart';

You can now reference the methods within the calendar.dart file.

Image carousel action plugin

The Carousel action plugin that is provided in the Acoustic Mobile app messaging sample app lets you add a "carousel" of photos and videos to mobile app messages.
When a mobile app message is sent to a device, a banner is displayed, which the mobile user can drag down or click on to open the first image.
When the notification is expanded, the first image will appear with its label. The label's text is the name of the image action. Under the image and the text, there will be two buttons: next and previous. Clicking on them will change the image to the next/previous image and the label to the next/previous image label.
Clicking on the image or the text removes the notification and performs the image action. The image slides into view from the right and the next image is downloaded in the background. Users move through the carousel's images by clicking the Next and Previous buttons.
The carousel payload contains an array of items with URLs and text, which correspond to the images that are displayed in the carousel.
The payload contains the following keys:

  • mutable-content - Executes the notification service extension when the mobile app message arrives on the device. The notification service creates the carousel action category and the actions specified by the carousel category, and then it delivers the mobile app message to the operating system for further processing.
  • category - Set to carousel.
  • notification-action - Set type to carousel. When a payload with a type of "carousel" is received by the device, the carousel action category is executed.
  • category-name - Set to carousel. The notification service creates an action category with the name "carousel".
  • category-actions - Specify the actions that you want. For example: next, prev, carousel, and open.
  • carousel block - Contains an item array where the URL and text for each item is specified. Items correspond to images that are displayed in the carousel.

๐Ÿ“˜

Note:

For notifications sent on Android, the mutable-content and category are not set.

To send the image carousel action, you need to send the following action payload.

{
    "aps": {
        "mutable-content": 1,
        "category": "carousel",
        "alert": {
            "title": "Testing Title",
            "subtitle": "Testing Subtitle",
            "body": "Testing Body"
        },
        "sound": "default"
    },
    "notification-action": {
        "type": "carousel"
    },
    "category-name": "carousel",
    "category-actions": [{
        "type": "next",
        "name": "Next"
    }, {
        "type": "prev",
        "name": "Previous"
    }, {
        "type": "carousel",
        "name": "Open",
        "destructive": false,
        "authentication": true,
        "foreground": true
    }],
    "carousel": {
        "items": [
            {"url": "https://acoustic.com/files/2020/05/hero_getting-back.jpg", "text": "Workspace"},
            {"url": "https://acoustic.com/files/2020/06/blog_what-marketers-want-1024x683.jpg", "text": "Connected"},
            {"url": "https://acoustic.com/files/2020/06/hero_blog-marketing-dbs-best-practices-1024x682.jpg", "text": "Building blocks"},
            {"url": "https://acoustic.com/files/2020/05/blog_hidden-preference.jpg", "text": "Capturing behaviors"},
            {"url": "https://acoustic.com/files/2020/05/blog_5-steps-identify-1024x640.jpg", "text": "Interactive email"}
        ]
    }
}

Install the image carousel action plugin

Carousel is implemented as a dynamic action category that includes the next, prev, carousel, and open category-actions. The carousel category-action contains an array of items with urls and text, which correspond to the images that are displayed in the carousel. The mutable-content flag in the app's notification service enables the app to intercept and pre-process mobile app messages before presenting them to users.

๐Ÿ“˜

Note:

If you use images that are too large, iOS kills the carousel plugin. Apple does not document the size limitation. Ensure that you consider the size limitation when using the carousel plugin.

Complete the following steps to add the image carousel action plugin to your iOS project:

  1. Open the Xcode project and select File > New > Target.
  2. Select Notification Content Extensionand click Next.
  3. Select Carousel as the product name, ObjC as the language, and click Finish.
  4. Replace the contents of 'NotificationViewController.h', 'NotificationViewController.m', 'MainInterface.storyboard', and 'info.plist' with the files in the Image Carousel Plugin folder.
  5. Select Carousel Target and setup code signing by selecting a Team in the General Tab.
  6. Add 'CarouselAction.h' and 'CarouselAction.m' to Application Target.
  7. Register the carousel plugin in the application delegate AppDelegate.m file.
  8. Add carouselAction.h to the list of import statements.
    
    
    // Action Plugins #import "ActionMenuPlugin.h" #import "AddToCalendarPlugin.h" #import "AddToPassbookPlugin.h" #import "SnoozeActionPlugin.h" #import "DisplayWebViewPlugin.h" #import "TextInputActionPlugin.h" #import "ExamplePlugin.h" #import "CarouselAction.h" // add this line // MCE Inbox Plugins #import "MCEInboxActionPlugin.h" #import "MCEInboxPostTemplate.h" #import "MCEInboxDefaultTemplate.h" // MCE InApp Plugins #import "MCEInAppVideoTemplate.h" #import "MCEInAppImageTemplate.h" #import "MCEInAppBannerTemplate.h"
  9. Add [CarouselAction registerPlugin]; to either init or application:didfinishlaunchingwithoptions:
    
    
    // MCE Inbox plugins [MCEInboxActionPlugin registerPlugin]; [MCEInboxPostTemplate registerTemplate]; [MCEInboxDefaultTemplate registerTemplate]; // MCE InApp Plugins [MCEInAppVideoTemplate registerTemplate]; [MCEInAppImageTemplate registerTemplate]; [MCEInAppBannerTemplate registerTemplate]; // Action Plugins [ActionMenuPlugin registerPlugin]; [ExamplePlugin registerPlugin]; [AddToCalendarPlugin registerPlugin]; [AddToPassbookPlugin registerPlugin]; [SnoozeActionPlugin registerPlugin]; [DisplayWebViewPlugin registerPlugin]; [TextInputActionPlugin registerPlugin]; [CarouselAction registerPlugin]; // add this line

Like all expandable notifications, the Carousel plugin works only on Android 5 (API 21, Lollipop) and higher. If a carousel message is sent to a device with a lower version of Android, a simple notification will be displayed, and the action will be the first image action.

  1. Open your Android Studio project.
  2. Add carousel.json to your assets/mce.plugins directory.
  3. Add acoustic-mobile-push-android-sdk-plugin-carousel-3.8.0.jar to your project's libs directory.
  4. Copy the mcecarousel*.png images into your res/drawable directory.
  5. Copy mce_carousel_notification.xml into your res/layout directory.
  6. Send a carousel action through the API:
    
    
    { "next": "<text of next image button>", "prev": "<text of previous image button>", "carousel": <array of carousel actions> (carousel action is ) }

The carousel action is:


{ "image": "<image url>", "action": <mce action element> }

Add to passbook action plugin ( iOS only)

The Add to Passbook plugin allows a user to add a pass to Passbook with a single click.
To send Add to passbook action, you need to send the following action payload.

{
"value": "<url>" // url of server that can vend the pass (https only)
"type": "passbook" // Constant
}

Install the Add to passbook action plugin

-(instancetype)init
{
  if(self = [super init])
  {
    [AddToPassbookPlugin registerPlugin];
  }
  return self;
}

Action menu plugin ( iOS only)

The Action Menu plugin displays a list of available actions as the target of an action. It registers with the showactions dynamic action type.

Text input action plugin ( Android only)

You can create and send notifications that prompt users for text. When the user receives the input notification, the user clicks an action that expands and displays a text input field. After the user enters text into the field, the notification is canceled.
Android N devices and Android M (and lower devices) require different implementations for text input notifications. For Android N devices, you implement text input notifications by using the input notification action type in an expandable notification action. For Android M devices (and lower), you implement a retrieval mechanism that receives text inputs and cancels the notification.

Android N devices

Create an input notification action by overriding 'co.acoustic.mobile.push.sdk.api.notification. MceNotificationAction' with the following code, which extends 'co.acoustic.mobile.push.sdk.api.notification.MceNotificationAction.Handling' with the direct reply:

public void handleAction(Context context, String input, String type,
    String name, String attribution, Map payload,  boolean fromNotification);

Android M (and lower) devices

  1. Implement co.acoustic.mobile.push.sdk.api.notification.MceNotificationInput and return an instance in the following method:
public MceCustomNotificationInput getCustomInput();
  1. Configure the following method to retrieve the text input and call the action when the user clicks the action.
public void createCustomInput(Context context, String type, String name,
    String attribution, Map payload)

Custom actions

You can customize the plugins provided to create custom actions or create custom action plugins. You can create your own custom action notification implementation for new action types. Custom action notifications override the predefined action types in the SDK, such as dial, URL, and openApp.

Custom action methods are defined by the developer and run when an action is selected by the user with the registered type value. An example of this would be for the developer to create a method that handles viewProduct action types. The developer registers that method with the MCEActionRegistry system. Then, a push message comes in with the "notification-action" set to type="viewProduct", and the app user opens the mobile app message.

Requirements for custom action types

When a custom action type for a mobile app message is used, the marketer must also include the destructive, authentication, and foreground keys in the action definition.

The "aps" section is used for system displayed notifications.

The {{type}} of action can be anything. Predefined action types include "dial" and "url". If the {{type}} is "rich", "dial", or "url", then the destructive is false, authentication is false, and foreground is true; otherwise, those attributes need to be included.

The {{value}} depends on the type of action. If the type is "dial", then the value is a phone number to be dialed. If the type is "url", then the value is the url that is to be viewed. If the type is "rich", then the value is the rich content ID to be displayed. When the type is anything else, it is handled by the plug-in that is defined for that type.

The {{name}} of the action is the title that shows on the button. If the {{type}} is not "rich", "dial", or "url", the following keys need to be defined in the action:

  • {{destructive}} can be either true or false. This sets the style of the action button.

  • {{authentication}} can be either true or false. This allows actions to be performed with the device is locked when true.

  • {{foreground}} can be either true or false. If it is true, then the app is opened when a selection is made. If it is false, then the app is not opened.

Create custom actions

The iOS SDK provides three custom actions that you can implement:

  • Custom action using a single argument type payload
  • Custom action using an action payload and a full iOS payload
  • Custom action for text entry fields

The following example shows implementing a custom action using a single argument type. You can customize your dynamic action category types by registering your object and selector with the MCEActionRegistry class. See the following code example:


-(instancetype)init { if(self=[super init]) { MCEActionRegistry * registry = [MCEActionRegistry sharedInstance]; [registry registerTarget: [self sharedInstance] withSelector:@selector(customAction:) forAction: @"customAction"]; } return self; ]

When a notification is opened with the customAction type, your custom method is run.


-(void)customAction:(NSDictionary*)action { // Do something neat with the action payload here! }

Example of custom action using an action payload and full iOS payload. This custom action is demonstrated in the Action Menu plug-in in the sample app. The following code sample shows how to register the custom action.


MCEActionRegistry * registry = [MCEActionRegistry sharedInstance]; [registry registerTarget: [self sharedInstance] withSelector: @selector(executeAction:withPayload:) forAction: @"custom"];

The following code shows how to implement the custom action.


-(void)executeAction:(NSDictionary*)action withPayload:(NSDictionary*)payload { // the action dictionary contains the action that is being executed, eg: {"type": "custom", "value":"foo"} // the payload dictionary includes the full APNS payload, e.g. {"aps": {...}} }

You can create your own custom action notification implementation for new action types. Custom action notifications override the pre-defined action types in the SDK, such as dial, url, and openApp.

  1. To create a custom action notification, you must implement co.acoustic.mobile.push.sdk.api.notification.MceNotificationAction.
    
    
    import co.acoustic.mobile.push.sdk.api.notification.MceNotificationAction public class MyCustomAction implements MceNotificationAction { /** * This method is called when a notification action is clicked. * @param context The application context * @param type The notification action type * @param name The notification action name (can be null) * @param attribution The notification attribution (can be null) * @param payload The notification payload. The map contains the key value pairs from the notification action payload. * @param fromNotification true if this action is called from a notification and false otherwise */ public void handleAction(Context context, String type, String name, String attribution, Map payload, boolean fromNotification) { // your implementation here } /** * Initiates the action with the given options * @param context The application's context * @param initOptions The initialization options */ public void init(Context context, JSONObject initOptions){ // your implementation here } /** * Updates the action with the given options - not is use yet * @param context The application's context * @param updateOptions The update options */ public void update(Context context, JSONObject updateOptions) { // your implementation here } /** * This method is called when a notification with this action as its main action. If it returns false, the notification will not be shown. * This can be used in case there are preparations needed before the notification can be shown. * @param context The application's context * @param notificationDetails The received notification * @param sourceBundle The bundle that contained the notification * @return true to show the notification and false to not show it */ public boolean shouldDisplayNotification(Context context, NotificationDetails notificationDetails, Bundle sourceBundle) { // your implementation here } }
  2. To register your custom action for a specific type, add the following code.
    
    
    import co.acoustic.mobile.push.sdk.api.notification.MceNotificationActionRegistry MceNotificationActionRegistry.registerNotificationAction("snooze", new MyCustomAction());

Action plugins can be used to extend the behavior executed when a message is interacted with. Push messages, InApp messages and Inbox messages all use actions to define what happens when a user interacts with them. You can register your own action handlers written in javascript using the registerAction function. (See the send-email-action.js in the sample application for an example).

Custom actions can also be written in javascript:


import {NativeEventEmitter} from 'react-native'; import {RNAcousticMobilePushActionHandler} from 'NativeModules'; const emitter = new NativeEventEmitter(RNAcousticMobilePushActionHandler); export default function demonstrationAction(details) { // details.action contains the specific action payload ie {"type": "demonstration", "value": "acoustic"} // details.payload contains the entire push payload ie { "aps": { "alert": "test" }, "notification-action": {"type": "demonstration", "value": "acoustic"} } // You can place code here to use the values in those payloads to perform work on behalf of the user } // The registerAction call tells the SDK that you intend to handle actions of this type. In addition the function passed will be called for any missed actions received while your code was not running. RNAcousticMobilePushActionHandler.registerAction('demonstration', demonstrationAction); // The listener call allows this function to be called when actions arrive emitter.addListener('demonstration', demonstrationAction);

To include custom actions in your application, you need to put them in a space separated list in the custom actions key in the config.xml file. After that is completed, you can register for callbacks to those actions through the MCEPlugin.setRegisteredActionCallback function. The callback includes both the action payload and the entire push payload for processing of that action.

  1. Implement a subclass of AcousticMobilePush.Forms.PushAction.
    
    
    public class CustomAction : PushAction { }
  2. Override the required Handle Action: method.
    
    
    public override void HandleAction (JObject action, JObject payload, string attribution, string mailingId, int id) {
  3. Register the custom action class with the action registry at Application subclass creation startup.
    
    
    SDK.Instance.RegisterAction(โ€œcustomActionโ€, new CustomAction());

To create a custom action, you must pass user input through a register() function and send it to the SDK. The Flutter SDK then registers it as a custom action.

  1. Import the following packages.
import 'package:flutter/material.dart'; import 'package:flutter_acoustic_mobile_push/flutter_acoustic_sdk_push.dart';
  1. Create local variable:
var value = CustomActionValue();
  1. Add the registerCustomAction function to send the data to the SDK.
Future<void> registerCustomAction(String actionType) async { value.registerCustomAction(actionType); value.registeredEvent.subscribe((args) { var data = args!.changedValue; print('registering'); print(data); setState(() { statusValue = data; }); }); }
  1. The register function then passes the user input data to the registerCustomAction function.
register() { _yourFormKeyHere.currentState?.save(); if (_customActionType == null) { return Text(statusValue, style: TextStyle(color: labelColor)); } else { registerCustomAction("CoolAction"); } }

In the example above, we are creating and registering a custom action called "CoolAction".

  1. To unregister a custom action, add the unregister function. The unregister function then passes the user input data to the unregisterCustomAction function.
Future<void> unregisterCustomAction(String actionType) async { value.unregisterCustomAction(actionType); value.unregisiteredEvent.subscribe((args) { var data = args!.changedValue; setState(() { statusValue = data; }); }); }

๐Ÿ“˜

Note:

The register function must be tied to a register button or inkwell widget that is used to save the user input when the clicked or the tap action is performed.

For more information about registerCustomAction functionality, see
flutter_acoustic_sdk_push.dart

Override Actions

You can override actions and replace an old action with a new one. If you assigned a key to the actionType and did not use the default key to map the action to the SDK, you must first unregister the key and then assign a new one.

  1. Add the unregisterCustomAction function from the SDK.
Future<void> unregisterCustomAction(String actionType) async { value.unregisterCustomAction(actionType); value.unregisteredEvent.subscribe((args) { var data = args!.changedValue; setState(() { statusValue = data; }); }); }
  1. Add the unregister function.
unregister() { _yourFormKeyHere.currentState?.save(); unregisterCustomAction(_customActionType); }
  1. After unregistering the action type, you should now be able to register a new action type and override/update the key for the map (value) of the previous action.
    For more information, see

Did this page help you?