DEV Community

HarmonyOS
HarmonyOS

Posted on

How to Open Bluetooth Settings via App Linking

Read the original article:How to Open Bluetooth Settings via App Linking

Question

How can I use App Linking to open the system Bluetooth settings for pairing?

Short Answer

Call startAbility() with a Want targeting the Bluetooth settings URI (bluetooth_entry) in the system settings app.

Applicable Scenarios

When your app needs to redirect users to the Bluetooth pairing interface—commonly used in smart device or accessory setup flows.

Code Example

let context = getContext(this) as common.UIAbilityContext;

let want: Want = {

  bundleName: 'com.huawei.hmos.settings',

  abilityName: 'com.huawei.hmos.settings.MainAbility',

  uri: 'bluetooth_entry'

};



context.startAbility(want)

  .then(() => {

    console.info('Bluetooth settings opened');

  })

  .catch((err: BusinessError) => {

    console.error(`Failed to open Bluetooth settings. Code: ${err.code}, message: ${err.message}`);

  });
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

Use startAbility() with a Want that targets the system settings app’s bluetooth_entry URI to open the Bluetooth pairing screen. This is useful for guiding users directly to Bluetooth settings during device setup.

Reference Link

https://developer.huawei.com/consumer/en/doc/harmonyos-references/js-apis-inner-application-uiabilitycontext

Written by Emincan Ozcan

Top comments (0)