question

ackroo avatar image
ackroo asked ackroo commented

Issue with CFP Activity on Clover Duo

I am trying to present an Activity to the customer facing unit. I followed the instructions on https://docs.clover.com/docs/using-customer-facing-platform and ended up with the following files.


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.cfptestapp">

    <uses-permission android:name="com.clover.remote.terminal.permission.REMOTE_TERMINAL" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.CFPTestApp" >
        <activity android:name=".CFPDisplayActivity" >
            <intent-filter>
                <action android:name="com.example.cfptestapp.MainActivity" />
                <category android:name="com.clover.cfp.ACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java

public class MainActivity extends Activity {
    private  static final String TAG = MainActivity.class.getName();
    private static final String CUSTOM_ACTIVITY_NAME = "com.example.cfptestapp.CFPDisplayActivity";
    private Executor executor = Executors.newFixedThreadPool(3);
    private RemoteDeviceConnector remoteDeviceConnector;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        remoteDeviceConnector = new RemoteDeviceConnector(this, CloverAccount.getAccount(this));
    }
    @Override protected void onResume() {
        super.onResume();
        final String payload = "{\"msg\"=\"Initial...\"}"; // if you need an inital payload
        final CustomActivityRequest car = new CustomActivityRequest(CUSTOM_ACTIVITY_NAME, payload);
        executor.execute(()->{
            boolean connected = remoteDeviceConnector.connect();
            remoteDeviceConnector.resetDevice(new ResetDeviceRequest());
            remoteDeviceConnector.startCustomActivity(car, new CustomActivityListener(){
                @Override public void onMessageFromActivity(MessageFromActivity message) {
                    // handle message from the CustomActivity
                    Log.v(TAG, message.toString());
                }

                @Override public void onCustomActivityResult(CustomActivityResponse response) {
                    // handle the result of the CustomActivity
                    Log.v(TAG, response.toString());
                }
            });
        });
    }

    @Override protected void onPause() {
        super.onPause();
        executor.execute(()->{
            remoteDeviceConnector.sendMessageToActivity(new MessageToActivity(CUSTOM_ACTIVITY_NAME, "FINISH"));
            remoteDeviceConnector.disconnect();
        });
    }
}

CFPDisplayActivity.java

public class CFPDisplayActivity extends AppCompatActivity implements CloverCFPCommsHelper.MessageListener {
    CloverCFPActivityHelper activityHelper;
    CloverCFPCommsHelper commsHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cfpdisplay);

        activityHelper = new CloverCFPActivityHelper(this);
        commsHelper = new CloverCFPCommsHelper(this, getIntent(), this);
    }

    public void onDestroy() {
        activityHelper.dispose();
        commsHelper.dispose();
        super.onDestroy();
    }

    public void onMessage(String payload) {
        // called when remoteDeviceConnector.sendMessageToActivity(...)
        // is invoked from POS
        if ("FINISH".equals(payload)) {
            finishWithPayloadToPOS("");
        }
    }

    public void doSendMessageToPOS() {
        try {
            String payload = "some message";
            commsHelper.sendMessage(payload); // send a message to the RemoteDeviceConnector instance
        } catch (Exception e) {
            // log the excption, update ui, etc.
        }
    }

    public void finishWithPayloadToPOS(String resultPayload) {
        activityHelper.setResultAndFinish(RESULT_OK, resultPayload);
    }
}

Any help would be appreciated


station pro
7 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Richelle Herrli avatar image Richelle Herrli ♦♦ commented ·
Please specify what you would like help with.
0 Likes 0 ·
ackroo avatar image ackroo Richelle Herrli ♦♦ commented ·

Our application needs to display an Activity to the customer on Clover Duo's customer facing terminal after a a payment has been made. We have this working by listening to a broadcast for the clover 'PAYMENT_PROCESSED' intent for Mini and Flex Device's but need a solution for 2 screen setups


The code I posted is basically a copy of the clover doc instructions (so far as i know), if someone can explain where my error is and I can get the simple example working, I can figure the rest out on my own. The 'android-examples-clover' project on github has a 'clover-cfp-example' but it uses deprecated classes.

0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ ackroo commented ·
You haven't posted any errors or described the problem, so we can't provide you with any suggestions.
0 Likes 0 ·
Show more comments

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community