1

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

grendelb
  • 31
  • 2

2 Answers2

0

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.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • Thanks for answer. I will try to unregister reciver callback right after get permission to use WE. I still waiting for that from huawei dev team. – grendelb Feb 08 '22 at 09:11
0

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.

Zinna
  • 1,947
  • 2
  • 5
  • 20
  • Yes, WE API for wearable doesn't support cancel file transfer. It is async api and returns Task object. I will try to find some way to cancel by Task. But after quick look on Task api I doubt it will be possible. There is other way to cancel it. Just terminate Ability and all objects this way. However, I don't like this way. It is very ugly workaround. – grendelb Feb 08 '22 at 09:13