ability-startup-with-implicit-want.md 2.8 KB
Newer Older
G
Gloria 已提交
1 2
# Using Implicit Want to Open a Website

3
This section uses the operation of using a browser to open a website as an example. It is assumed that one or more browser applications are installed on the device. To ensure that the browser application can work properly, configure the [module.json5 file](../quick-start/module-configuration-file.md) as follows:
G
Gloria 已提交
4 5

```json
6 7 8 9
{
  "module": {
    // ...
    "abilities": [
G
Gloria 已提交
10 11
      {
        // ...
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
        "skills": [
          {
            "entities": [
              "entity.system.home",
              "entity.system.browsable"
              // ...
            ],
            "actions": [
              "action.system.home",
              "ohos.want.action.viewData"
              // ...
            ],
            "uris": [
              {
                "scheme": "https",
                "host": "www.test.com",
                "port": "8080",
                // Prefix matching is used.
                "pathStartWith": "query",
                "type": "text/*"
              },
              {
                "scheme": "http",
                // ...
              }
              // ...
            ]
          }
        ]
G
Gloria 已提交
41 42
      }
    ]
43 44
  }
}
G
Gloria 已提交
45 46
```

47
In the initiator UIAbility, use implicit Want to start the browser application.
G
Gloria 已提交
48

49 50
```ts
import common from '@ohos.app.ability.common';
G
Gloria 已提交
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
function implicitStartAbility() {
  let context = getContext(this) as common.UIAbilityContext;
  let wantInfo = {
    // Uncomment the line below if you want to implicitly query data only in the specific bundle.
    // bundleName: "com.example.myapplication",
    "action": "ohos.want.action.viewData",
    // entities can be omitted.
    "entities": ["entity.system.browsable"],
    "uri": "https://www.test.com:8080/query/student",
    "type": "text/plain"
  }
  context.startAbility(wantInfo).then(() => {
    // ...
  }).catch((err) => {
    // ...
  })
}
```
G
Gloria 已提交
70

71
The matching process is as follows:
G
Gloria 已提交
72

73 74 75 76
1. If **action** in the passed **want** parameter is specified and is included in **actions** under **skills** of the ability to match, the matching is successful.
2. If **entities** in the passed **want** parameter is specified and is included in **entities** under **skills** of the ability to match, the matching is successful.
3. If **uri** in the passed **want** parameter is included in **uris** under **skills** of the ability to match, which is concatenated into https://www.test.com:8080/query* (where * is a wildcard), the matching is successful.
4. If **type** in the passed **want** parameter is specified and is included in **type** under **skills** of the ability to match, the matching is successful.
G
Gloria 已提交
77

78
When there are multiple matching applications, a dialog box is displayed for you to select one of them. The following figure shows an example. 
79

80
![](figures/ability-startup-with-implicit-want1.png)