wearablesharmonyos

HarmonyOS wearable vibrator not activating


I'm creating a HarmonyOS Wearable app using the JS Framework and I want to use the vibrator. The watch definitely has a vibrator because I can feel it when I use the scroll weel in the settings app.

So I requested the system_grant ohos.permission.VIBRATE permission in the config.json file as described here

"module": {
...
    "reqPermissions": [
      {
        "name": "ohos.permission.VIBRATE",
        "reason": "Make vibrates"
      }
    ]
...
}

Then it should be simple to use the imported vibrator like this

import vibrator from '@system.vibrator';
export default {
    // ...
    onShow() {
        console.log("VIBRATOR");
        vibrator.vibrate({
            mode : "long",
            success: () => console.debug("Vibrator Success"),
            fail : (data, code) => console.log("Vibrator handle fail, data = ${data}, code = ${code}"),
            complete : () => console.debug("Vibrator Complete")
        });
    }
    // ...
}

I do get the VIBRATOR log in HiLog but non of the other logs in the vibrator callbacks nor does the device vibrate.

Does anyone know what I'm doing wrong?

EDIT: I noticed a bunch of error logs after the VIBRATOR log. I cant figure out what they mean so I'm posting them here.

D 03B00/JSApp: app Log: VIBRATOR
E 03900/Ace: [<private>      (<private>)] ace Log: [JS Framework] Failed to invoke the event handler of "viewappear" on div (_root):
E 03900/Ace:  TypeError: value has no property
E 03900/Ace: [<private>      (<private>)] Qjs FireAsyncEvent FAILED !! jsCall: <private>
E 03900/Ace: [<private>       (<private>)] [DUMP] <private>
E 03900/Ace: [<private>       (<private>)] <private>

Solution

  • The JS API document is written based on the wearables. The standard usage of smart devices is as follows:

    vibrator.vibrate({
        mode: "short"
    });
    

    or

    vibrator.vibrate();