I am working on an app where my requirement is to transfer some files from one device to another. I am using Google's Nearby Connections API for this. As per the app requirement, when the advertiser (Receiver) receives the complete data, I need to send an acknowledegment to the Discoverer (Sender) in order to perform some operations on it. So can someone guide me through how it can be done?

1

There are 1 best solutions below

3
On

If you only want to be notified when the advertiser received the data you sent, you can use the callback onPayloadTransferUpdate which works like a notification/acknowledgement about a payload transfer. You can do something like this:

private PayloadCallback payloadCallback =
            new PayloadCallback() {
                @Override
                public void onPayloadReceived(@NonNull String endpointId, @NonNull Payload payload) {

                }

                @Override
                public void onPayloadTransferUpdate(@NonNull String endpointId, @NonNull PayloadTransferUpdate payloadTransferUpdate) {
                    if (payloadTransferUpdate.getStatus() == PayloadTransferUpdate.Status.SUCCESS) {
                        // handle payload transfer success event - ACK
                    } else if (payloadTransferUpdate.getStatus() == PayloadTransferUpdate.Status.FAILURE) {
                        // handle payload transfer fail event - NAK
                    } else {
                        // handle other events like CANCELED and IN_PROGRESS
                    }
                }
            };