Intents and Broadcasts

The Clover platform uses the Android Intents system to allow third party apps to integrate more deeply with Clover’s base activities. These intents fall under three categories of usage:

  • Clover Activity Intents: Used by your app to launch basic Clover activities with Android’s startActivity()
  • Clover Broadcasts:  Broadcast by Clover apps when certain events occur, which your app may react to
  • Action Intents: Set as the action for your activity’s intent filter, giving merchants the option to launch your app from the transaction flow

Documentation for all of Clover’s public intents can be found here: http://clover.github.io/clover-android-sdk/com/clover/sdk/v1/Intents.html

 

Clover Activity Intents

These intents can be used with the startActivity, or startActivityForResult methods to launch one of the Activities of a core Clover app, allowing you to pass responsibility for certain functionality to the base Clover workflow. Extra’s can be passed along with these intents with additional data and options.

Sample (Intents.ACTION_START_REGISTER):

This intent allows you to launch the base register activity, as well as optionally pass an Order ID or customer JSON that will be associated with the Register session.

Intent intent = new Intent(Intents.ACTION_START_REGISTER);
intent.putExtra(Intents.EXTRA_ORDER_ID, "PTEXTPYDZ6K4C");
startActivity(intent);

 

OR

Intent intent = new Intent(Intents.ACTION_START_REGISTER);
String customerJson = "{'id': 'MDGRBQZN6C9V0', 'emailAddresses': [{'id': '2JVY19VDH9SAW','emailAddress': 'test@clover.con'}]}";
intent.putExtra(EXTRA_CUSTOMER_V3, customerJson);
startActivity(intent);

Other Examples:

Clover Activity Intents are used in the following examples:

 

Clover Broadcasts

Clover emits broadcasts when important events occur, such as the creation of new orders or payments. Your application can register a broadcast receiver in order to listen and respond to these events.

Sample (Intents.ACTION_ORDER_CREATED):

By setting a listener for this intent your app will be triggered whenever an order has been created, and will receive the id of the new order.

public class MyReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(Intents.ACTION_ORDER_CREATED)) {
      String orderId = intent.getStringExtra(Intents.EXTRA_CLOVER_ORDER_ID);
    }
  }
}

Other Examples:

Clover Broadcasts are used in the following examples:

 

Action Intents

If you set one of these intents as the action for your activity’s intent filter the Clover system apps will register your app as a listener for that intent. Typically this relationship will be used by one or more of the Clover base apps to interface with your app’s activity. For instance, the following sample code registers an activity as a listener for the Intents.ACTION_MODIFY_ORDER intent, meaning that the merchant facing pay screen will display a button with your label value that will launch your activity, passing the ID of the order to be modified.

Sample (Intents.ACTION_MODIFY_ORDER):

This intent will allow your app to slot into the standard Clover payment flow and work with an order before passing back to Clover for finalization and payment.

<!--In AndroidManifest.xml Application-->

<activity
    android:name=".ModifyOrderActivity"
    android:label="@string/title_activity_modify_order">
    <intent-filter>
        <action android:name="clover.intent.action.MODIFY_ORDER"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

 

// In ModifyOrderActivity onCreate()

String orderId = getIntent().getStringExtra(Intents.EXTRA_ORDER_ID);

Other Examples:

Action Intents are used in the following examples: