Start the UIAbility of other applications in the device (implicit Want start) [Nut Pie]

 

Launch the UIAbility of other applications in the device (implicit Want launch)

 

Effect:

https://www.bilibili.com/video/BV1q8411Q7Sz/

 

1. Install multiple document applications to be matched to the device, and configure the entities field and actions field of the skills tag in the module.json5 configuration file corresponding to UIAbility.

For example mine is

{
  "module": {
    "abilities": [
      {
        ...
        "skills": [
          {
            "entities": [
          
              "entity.system.default"
            ],
            "actions": [
     
              "ohos.want.action.viewData"
            ]
          }
        ]
      }
    ]
  }
}

2. The entities and actions in the caller's want parameter need to be included in the entities and actions of the skills configuration of the UIAbility to be matched. After the system matches the UIAbility that meets the parameters of entities and actions, a selection box will pop up to display the list of matched UIAbility instances for the user to choose and use.

import common from '@ohos.app.ability.common';
          let context = getContext(this) as common.UIAbilityContext;; // UIAbilityContext
          let want = {
​
​
//隐式Want启动
//             action: 'ohos.want.action.viewData',
//             // entities can be omitted.
//             entities: ['entity.system.default'],
          }
          // context为调用方UIAbility的UIAbilityContext
          context.startAbility(want).then(() => {
​
            console.info('Succeeded in starting ability.');
          }).catch((err) => {
            console.error(`Failed to start ability. Code is ${err.code}, message is ${err.message}`);
          })
        })

 

Then install the two apps and you're done.

 

Finally, let's look at the effect.

image-20230822090403027

Attachment: common actions and entities

action: Indicates the generic action to be performed by the caller (such as view, share, app details). In the implicit Want, you can define this field and cooperate with uri or parameters to indicate the operation to be performed on the data. If enabled, view the uri data. For example, when the uri is a URL and the action is ohos.want.action.viewData, it means that the application component that can view the URL is matched. Declaring the action field in Want indicates that the callee application is expected to support the declared operation. Declaring actions in the skills field of the callee application configuration file indicates that the application supports the declared operations.

common actions

  • ACTION_HOME: The action of starting the application entry component, which needs to be used in conjunction with ENTITY_HOME; the system desktop application icon is the explicit entry component, and clicking it also starts the entry component; multiple entry components can be configured.

  • ACTION_CHOOSE: Select local resource data, such as contacts, photo albums, etc.; the system generally has corresponding Picker applications for different types of data, such as contacts and galleries.

  • ACTION_VIEW_DATA: View data, when the URL uri is used, it means to display the content corresponding to the URL.

  • ACTION_VIEW_MULTIPLE_DATA: The action of sending multiple data records.

entities : Indicates the category information of the target application component (such as browser, video player), and is a supplement to action in the implicit Want. In Implicit Want, developers can define this field to filter the category of matching applications, for example, it must be a browser. Declaring the entities field in Want indicates that the called-side application is expected to belong to the declared category. The entites declared in the skills field of the called application configuration file indicate the categories supported by the application.

common entities

  • ENTITY_DEFAULT: The default category is meaningless.

  • ENTITY_HOME: Home screen has icon click entry category.

  • ENTITY_BROWSABLE: Indicates the browser category.

     

Guess you like

Origin blog.csdn.net/qq_39132095/article/details/132421252