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