Wear Engine how to cancel/abort file sending on wearable (Java)?

Viewed 68

I use Wear Engine to send files from watch (HarmonyOS) to phone (Android). I can't find any method to cancel/abort file transfer. I imagine a file can weigh many megabytes and there is no option to stop the bytes transfer.

P2pClient object doesn't expose any method to cancel file sending. P2pClient send() method returns Task result but I was unable to find here any way to stop this Task returned by P2pClient.

Wear Engine API Java

2 Answers

Call the unregisterReceiver method to cancel the reception of messages or files from your wearable app. The principle behind this is to unregister a listener for Wear Engine.

// Step 6: Your phone app cancels receiving the messages or files sent by the wearable app.
HiWear.getP2pClient(this).unregisterReceiver(receiver)
    .addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void successVoid) {
            // Your phone app cancels the reception of messages or files.
        }
    })
    .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(Exception e) {
            // Your phone app fails to cancel the reception of messages or files.
        }
    });

For more info, pls refer to this docs.

After further investigating Wear Engine, it seems to me that there is no such API for canceling a file sending from watch app to phone app. Wear Engine has an API, cancelFileTransfer, for canceling a file transfer from phone app to watch app. I am not sure if the unregister on watch app can stop the file transfer.

Related