Register an action through a JSON file

You can also register a custom action using a JSON file.

  1. Create a test.json file in mce.plugins that maps the action to the class that will be called when the action is taken.
{
  'notification-actions': [
    {
    'type': 'test',
    'class': 'co.acoustic.mobile.push.samples.gcm.TestAction'
    },
    {
    'type': 'test2',
    'class': 'co.acoustic.mobile.push.samples.gcm.TestAction2'
    },
//.. Register Other actions
  ]
}
Filename isn't really important, but must end in .json
  1. Create the classes that handle the action.
{
  "notification-actions": [
    {
    "type": "test",
    "class": "co.acoustic.mobile.push.samples.gcm.TestAction"
    },
    {
    "type": "test2",
    "class": "co.acoustic.mobile.push.samples.gcm.TestAction2"
    },
//.. Register Other actions
  ]
}
Filename isn't really important, but must end in .json

    Create the classes that handle the action

TestAction.java (similarly TestAction2.java for the 2nd custom action)
package co.acoustic.mobile.push.samples.gcm;
import android.content.Context;
import android.os.Bundle;
import co.acoustic.mobile.push.sdk.api.notification.NotificationDetails;
import co.acoustic.mobile.push.sdk.api.notification.MceNotificationAction;
import org.json.JSONObject;
import java.util.Map;

public class TestAction implements MceNotificationAction {
    private static final String TAG = "TestAction";
   /*
      This method implements the "test" action.
      @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 time value.
     /
    @Override
    public void handleAction(Context context, String type, String name, String attribution, Map<String, String> payload, boolean fromNotification) {
        System.out.println(TAG + ": " + payload.toString());
    }
    @Override
    public void init(Context context, JSONObject initOptions) {
    }
    @Override
    public void update(Context context, JSONObject updateOptions) {
    }
    @Override
    public boolean shouldDisplayNotification(Context context, NotificationDetails notificationDetails, Bundle sourceBundle) {
        return true;
    }
}
  1. In Acoustic Campaign Automation, create the action that sends the appropriate fields.
"{
'label': 'Test Action',
'type': 'test',
'inputRequired': true,
'value': null,
'description': 'Prints the action',
'placeholder': 'Enter placeholder',
'templateId': 1232,
'authenticationRequired': false,
'activationMode': false
},
{
'label': 'Test Action2',
'type': 'test2',
'inputRequired': true,
'value': null,
'description': 'Prints the action',
'placeholder': 'Enter placeholder',
'templateId': 1232,
'authenticationRequired': false,
'activationMode': false
},

📘

Note:

The ‘type’ in the .json must match ‘type’ in the action.

  1. Add your action to a notification. It is not necessary to add the action to the Android manifest.
  2. Click the action to accept it. The following is displayed:
08-22 14:16:54.946 30209-30209/co.acoustic.mobile.push.samples.gcm I/System.out: TestAction: {value={}, co.acoustic.mobile.push.sdk.NOTIF_SOURCE_PAYLOAD={'attribution':'Simple with my action'}, co.acoustic.mobile.push.sdk.NOTIF_SOURCE={'subject':'Simple title','message':'Simple message','notification-action':{'name':'Test Action','type':'test','value':{}},'highPriority':false,'sensitive':false}, co.acoustic.mobile.push.sdk.NOTIF_SOURCE_ID=404167564}