Read the original article:Unable to connect to wearable devices
Unable to connect to wearable devices
Problem Description
When using the application, users are unable to connect to wearable devices such as smart watches/bracelets normally.
Background Knowledge
Wear service error code: 1008500006 The user did not agree to the privacy authorization.
When a user uses the sports health service on a device for the first time, the user is required to agree to the sports health service privacy agreement. The current privacy authorization depends on the sports health app. The user needs to be guided to open the sports health app and complete the privacy authorization.
Problem Location
After reproducing the problem, search for keywords in the log CheckOrRequestPermission fail.
Analysis Conclusion
The error message "User privacy is not agreed" indicates that the user has not agreed to the sports health privacy authorization, resulting in the inability to connect to the wearable device.
Suggestion
1.Add the querySchemes field in the module.json5 file and configure "huaweischeme" in the list.
"huaweischeme" is the scheme of the Sports Health App homepage that needs to be redirected, as shown below:
{
"module": {
"name": "entry",
"type": "entry",
"description": module description,
"mainElement": "EntryAbility",
"deviceTypes": {...},
"querySchemes": [
"huaweischeme"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [...],
"metadata": [...]
}
}
2.Import relevant functional modules.
import { bundleManager, common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { productViewManager } from '@kit.StoreKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
3.Call canOpenLink to determine whether the Sports Health App is installed.
If it is already installed, call the openLink interface to launch the Sports Health App;
The application market recommendation interface is not installed to guide users to download the sports and health app.
try {
let result = bundleManager.canOpenLink('huaweischeme://healthapp/home/main');
let context = globalThis.context as common.UIAbilityContext;
if (result) {
// Open the home page of the Huawei Health app to request privacy permission
let link: string = 'huaweischeme://healthapp/home/main';
await context.openLink(link)
} else {
// Open the AppGallery recommendation to guide the user to download the Huawei Health app for privacy permission
const wantParam: Want = {
parameters: {
bundleName: 'com.huawei.hmos.health'
}
};
const callback: productViewManager.ProductViewCallback = {
onError: (error: BusinessError) => {
hilog.error(0x0001, 'TAG', `Failed to open AppGallery. Code: ${error.code}, message: ${error.message}`);
}
}
productViewManager.loadProduct(context, wantParam, callback);
}
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to agree user privacy. Code: ${err.code}, message: ${err.message}`);
}
Top comments (0)