1

我试图像我们通过android一样传递能力

Intent intent = new Intent(HomeActivity.this, cls);

但是在 Harmony 中,我们必须使用操作生成器,所以使用了这种方法

intent = new Intent();
Operation operation = new Intent.OperationBuilder().withBundleName(ability.getBundleName()).withAbilityName(name.toString()).build();
intent.setOperation(operation);

这里的'name'变量是类名。

我只是想知道这是否相当于上面的android代码。如果不是,那么正确的方法是什么

4

1 回答 1

0

您可以使用指定的 bundleName 和 abilityName 构造一个 Operation 对象来启动和导航到特定的能力。示例代码片段如下:

Intent intent = new Intent();

// Use the OperationBuilder class of Intent to construct an Operation object and set the deviceId (left empty if a local ability is required), bundleName, and abilityName attributes for the object.
Operation operation = new Intent.OperationBuilder()
        .withDeviceId("")
        .withBundleName("com.demoapp")
        .withAbilityName("com.demoapp.FooAbility")
        .build();

// Set the created Operation object to the Intent as its operation attribute.
intent.setOperation(operation);
startAbility(intent);

有关更多详细信息,请参阅此文档

于 2021-10-18T08:07:10.023 回答