目录

How does an application check whether another application is installed?

To enable application A to check whether application B is installed on the device and consequently determine whether to prompt the user to download application B, perform the following configurations:

In the module.json5 file of the entry module in application B, add the following configuration with this tag path: module -> abilities -> skills -> uris.

"uris": [
  {
    "scheme":"schB",
    "host":"com.example.test",
    "path":"open",
  }
],

In the module.json5 file of the entry module in application A, add the following configuration with this tag path: module -> querySchemes.

"querySchemes": [
  "schB"
],

Application A can then check whether application B is installed on the device.

import { hilog } from '@kit.PerformanceAnalysisKit';
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  // Application A determines whether Application B is installed on the device
  isAppBExist() {
    let exist = false;
    try {
      let link = 'schB://com.example.test/open';
      let data: boolean = bundleManager.canOpenLink(link);
      hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
      exist = data;
    } catch (err) {
      let message = (err as BusinessError).message;
      hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
      exist = false;
    }
    console.info('Has application B been installed:' + exist);
  }

  @State text: string = 'isAppBExist'

  build() {
    Row() {
      Column() {
        Text(this.text)
          .fontSize(30)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            this.isAppBExist();
          });
      }
      .width('100%')
    }
    .height('100%')
  }
}

Reference

bundleManager.canOpenLink