提交 16f59daa 编写于 作者: C chenyuyan

Merge branch 'master' into idlDocs

Change-Id: I472d1cb41c3a81174b953586d815a7e78c69b489
...@@ -150,24 +150,23 @@ OpenHarmony IDL容器数据类型与Ts数据类型、C++数据类型的对应关 ...@@ -150,24 +150,23 @@ OpenHarmony IDL容器数据类型与Ts数据类型、C++数据类型的对应关
## 开发步骤 ## 开发步骤
### IDL工具的获取 ### IDL工具的获取
首先,打开DevEco Studio—>Tools—>SDK Manager,查看OpenHarmony SDK的本地安装路径,如下图所示。 首先,打开DevEco Studio—>Tools—>SDK Manager,查看OpenHarmony SDK的本地安装路径,此处以DevEco Studio 3.0.0.993版本为例,查看方式如下图所示。
![SDKpath](./figures/SDKpath.png) ![SDKpath](./figures/SDKpath.png)
![SDKpath](./figures/SDKpath2.png) ![SDKpath](./figures/SDKpath2.png)
进入对应路径后,查看toolchains->3.x.x.x(对应版本号命名文件夹)下是否存在idl工具的可执行文件,若不存在,可对应版本前往[docs仓版本目录](https://gitee.com/openharmony/docs/tree/master/zh-cn/release-notes)下载SDK包,以[3.2Beta3版本](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v3.2-beta3.md#%E4%BB%8E%E9%95%9C%E5%83%8F%E7%AB%99%E7%82%B9%E8%8E%B7%E5%8F%96)为例,可通过镜像站点获取。 进入对应路径后,查看toolchains->3.x.x.x(对应版本号命名文件夹)下是否存在idl工具的可执行文件,若不存在,可对应版本前往[docs仓版本目录](https://gitee.com/openharmony/docs/tree/master/zh-cn/release-notes)下载SDK包,以[3.2Beta3版本](https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v3.2-beta3.md#%E4%BB%8E%E9%95%9C%E5%83%8F%E7%AB%99%E7%82%B9%E8%8E%B7%E5%8F%96)为例,可通过镜像站点获取。
关于如何替换DevEco Studio的SDK包具体操作,参考[full-SDK替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/full-sdk-switch-guide.md#full-sdk%E6%9B%BF%E6%8D%A2%E6%8C%87%E5%8D%97) 关于如何替换DevEco Studio的SDK包具体操作,参考[full-SDK替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/full-sdk-switch-guide.md#full-sdk%E6%9B%BF%E6%8D%A2%E6%8C%87%E5%8D%97)中的替换方法
得到idl工具的可执行文件后,根据具体场景进行后续开发步骤。 得到idl工具的可执行文件后,根据具体场景进行后续开发步骤。
### C++开发步骤 ### TS开发步骤
#### 创建.idl文件 #### 创建.idl文件
开发者可以使用C++编程语言构建.idl文件。 开发者可以使用TS编程语言构建.idl文件。
例如,此处构建一个名为IIdlTestService.idl的文件,文件内具体内容如下:
例如,此处构建一个名为iTest.idl的文件,文件内具体内容如下:
```cpp ```cpp
interface OHOS.IIdlTestService { interface OHOS.IIdlTestService {
...@@ -176,199 +175,23 @@ OpenHarmony IDL容器数据类型与Ts数据类型、C++数据类型的对应关 ...@@ -176,199 +175,23 @@ OpenHarmony IDL容器数据类型与Ts数据类型、C++数据类型的对应关
} }
``` ```
通过idl的可执行文件所在文件夹下执行命令 `idl -gen-cpp -d dir -c dir/IIdlTestService.idl`(-d后的dir为目标输出目录)在执行环境的dir目录中生成接口文件、Stub文件、Proxy文件。 在idl的可执行文件所在文件夹下执行命令 `idl -gen-ts -d dir -c dir/IIdlTestService.idl`
> **注意**:生成的接口类文件名称和.idl文件名称保持一致
以命名为`IIdlTestService.idl`的.idl文件,在输出文件夹为生成文件IIdlTestServiceCpp中生成的代码目录结构例类似于:
```
├── IIdlTestServiceCpp # idl代码输出文件夹
│ ├── i_idl_test_service.h # 生成文件
│ ├── idl_test_service_proxy.h # 生成文件
│ ├── idl_test_service_stub.h # 生成文件
│ ├── idl_test_service_proxy.cpp # 生成文件
│ └── idl_test_service_stub.cpp # 生成文件
└── IIdlTestService.idl # 构造的.idl文件
```
#### 服务端公开接口
OpenHarmony IDL工具生成的Stub类是接口类的抽象实现,并且会声明.idl文件中的所有方法。 -d后的dir为目标输出目录,以输出文件夹名为IIdlTestServiceTs为例,在idl可执行文件所在目录下执行`idl -gen-ts -d IIdlTestServiceTs -c IIdlTestServiceTs/IIdlTestService.idl`,将会在执行环境的dir目录(即IIdlTestServiceTs目录)中生成接口文件、Stub文件、Proxy文件。
```cpp > **注意**:生成的接口类文件名称和.idl文件名称保持一致,否则会生成代码时会出现错误。
#ifndef OHOS_IDLTESTSERVICESTUB_H
#define OHOS_IDLTESTSERVICESTUB_H
#include <iremote_stub.h>
#include "iidl_test_service.h"
namespace OHOS {
class IdlTestServiceStub : public IRemoteStub<IIdlTestService> {
public:
int OnRemoteRequest(
/* [in] */ uint32_t code,
/* [in] */ MessageParcel& data,
/* [out] */ MessageParcel& reply,
/* [in] */ MessageOption& option) override;
private:
static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0;
static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1;
};
} // namespace OHOS
#endif // OHOS_IDLTESTSERVICESTUB_H
```
开发者需要继承.idl文件中定义的接口类并实现其中的方法,同时在服务侧初始化时需要将定义的服务注册至SAMGR中,在本示例中,TestService类继承了IdlTestServiceStub接口类并实现了其中的TestIntTransaction和TestStringTransaction方法。具体的示例代码如下: 以名为`IIdlTestService.idl`的.idl文件、目标输出文件夹为IIdlTestServiceTs为例,其目录结构应类似于:
```cpp
#ifndef OHOS_IPC_TEST_SERVICE_H
#define OHOS_IPC_TEST_SERVICE_H
#include "hilog/log.h"
#include "log_tags.h"
#include "idl_test_service_stub.h"
namespace OHOS {
class TestService : public IdlTestServiceStub {
public:
TestService();
~TestService();
static int Instantiate();
ErrCode TestIntTransaction(int data, int &rep) override;
ErrCode TestStringTransaction(const std::string& data) override;
private:
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestService" };
};
} // namespace OHOS
#endif // OHOS_IPC_TEST_SERVICE_H
``` ```
├── IIdlTestServiceTs # idl代码输出文件夹
注册服务的示例代码如下: │ ├── i_idl_test_service.ts # 生成文件
│ ├── idl_test_service_proxy.ts # 生成文件
```cpp │ ├── idl_test_service_stub.ts # 生成文件
#include "test_service.h" │ └── IIdlTestService.idl # 构造的.idl文件
└── idl.exe # idl的可执行文件
#include <string_ex.h>
#include "if_system_ability_manager.h"
#include "ipc_debug.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
namespace OHOS {
using namespace OHOS::HiviewDFX;
int TestService::Instantiate()
{
ZLOGI(LABEL, "%{public}s call in", __func__);
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (saMgr == nullptr) {
ZLOGE(LABEL, "%{public}s:fail to get Registry", __func__);
return -ENODEV;
}
sptr<IRemoteObject> newInstance = new TestService();
int result = saMgr->AddSystemAbility(IPC_TEST_SERVICE, newInstance);
ZLOGI(LABEL, "%{public}s: IPC_TEST_SERVICE result = %{public}d", __func__, result);
return result;
}
TestService::TestService()
{
}
TestService::~TestService()
{
}
ErrCode TestService::TestIntTransaction(int data, int &rep)
{
ZLOGE(LABEL, " TestService:read from client data = %{public}d", data);
rep = data + data;
return ERR_NONE;
}
ErrCode TestService::TestStringTransaction(const std::string &data)
{
ZLOGE(LABEL, "TestService:read string from client data = %{public}s", data.c_str());
return data.size();
}
} // namespace OHOS
``` ```
#### 客户端调用IPC方法
C++客户端通常通过SAMGR获取系统中定义的服务代理,随后即可正常调用proxy提供的接口。示例代码如下:
```cpp
#include "test_client.h"
#include "if_system_ability_manager.h"
#include "ipc_debug.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
namespace OHOS {
int TestClient::ConnectService()
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (saMgr == nullptr) {
ZLOGE(LABEL, "get registry fail");
return -1;
}
sptr<IRemoteObject> object = saMgr->GetSystemAbility(IPC_TEST_SERVICE);
if (object != nullptr) {
ZLOGE(LABEL, "Got test Service object");
testService_ = (new (std::nothrow) IdlTestServiceProxy(object));
}
if (testService_ == nullptr) {
ZLOGE(LABEL, "Could not find Test Service!");
return -1;
}
return 0;
}
void TestClient::StartIntTransaction()
{
if (testService_ != nullptr) {
ZLOGE(LABEL, "StartIntTransaction");
[[maybe_unused]] int result = 0;
testService_->TestIntTransaction(1234, result); // 1234 : test number
ZLOGE(LABEL, "Rec result from server %{public}d.", result);
}
}
void TestClient::StartStringTransaction()
{
if (testService_ != nullptr) {
ZLOGI(LABEL, "StartIntTransaction");
testService_->TestStringTransaction("IDL Test");
}
}
} // namespace OHOS
```
### TS开发步骤
#### 创建.idl文件
开发者可以使用TS编程语言构建.idl文件。.idl示例如下:
```ts
interface OHOS.IIdlTestService {
int TestIntTransaction([in] int data);
void TestStringTransaction([in] String data);
}
```
使用者通过执行命令 “./idl -c IIdlTestService.idl -gen-ts -d /data/ts/” (-d为输出目录)在执行环境的/data/ts/目录中生成接口文件、Stub文件、Proxy文件。生成的接口类文件名称和.idl文件名称保持一致,区别在于其使用.ts扩展名。例如,IIdlTestService.idl 生成的文件名是 i_idl_test_service.ts、idl_test_service_proxy.ts、idl_test_service_stub.ts。
#### 服务端公开接口 #### 服务端公开接口
OpenHarmony IDL工具生成的Stub类是接口类的抽象实现,并且会声明.idl文件中的所有方法。 OpenHarmony IDL工具生成的Stub类是接口类的抽象实现,并且会声明.idl文件中的所有方法。
...@@ -557,137 +380,3 @@ export default class MySequenceable { ...@@ -557,137 +380,3 @@ export default class MySequenceable {
private str; private str;
} }
``` ```
## C++与TS互通开发步骤
### TS Proxy与C++ Stub开发步骤
#### C++端提供服务对象
1. 如上所述C++开发步骤,开发者使用C++编程语言构建.idl文件,通过命令生成接口、Stub文件、Proxy文件。
2. 开发者创建服务对象,并继承C++ Stub文件中定义的接口类并实现其中的方法,例如:
```cpp
class IdlTestServiceImpl : public IdlTestServiceStub {
public:
IdlTestServiceImpl() = default;
virtual ~IdlTestServiceImpl() = default;
ErrCode TestIntTransaction(int _data, int& result) override
{
result = 256;
return ERR_OK;
}
ErrCode TestStringTransaction(const std::string& _data) override
{
return ERR_OK;
}
};
```
#### C++端提供napi接口
C++需要通过napi的方式,把C++服务对象提供给TS端,例如:C++端提供一个GetNativeObject方法,方法里创建IdlTestServiceImpl实例,通过NAPI_ohos_rpc_CreateJsRemoteObject方法,创建出一个JS远程对象供TS应用使用,如下:
```cpp
NativeValue* GetNativeObject(NativeEngine& engine, NativeCallbackInfo& info)
{
sptr<IdlTestServiceImpl> impl = new IdlTestServiceImpl();
napi_value napiRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(reinterpret_cast<napi_env>(&engine), impl);
NativeValue* nativeRemoteObject = reinterpret_cast<NativeValue*>(napiRemoteObject);
return nativeRemoteObject;
}
```
#### TS端提供Proxy对象
如上所述TS开发步骤,开发者使用TS编程语言构建.idl文件,通过命令生成接口、Stub文件、Proxy文件。Proxy文件例如:
```ts
import {testIntTransactionCallback} from "./i_idl_test_service";
import {testStringTransactionCallback} from "./i_idl_test_service";
import IIdlTestService from "./i_idl_test_service";
import rpc from "@ohos.rpc";
export default class IdlTestServiceProxy implements IIdlTestService {
constructor(proxy) {
this.proxy = proxy;
}
testIntTransaction(data: number, callback: testIntTransactionCallback): void
{
let _option = new rpc.MessageOption();
let _data = new rpc.MessageParcel();
let _reply = new rpc.MessageParcel();
_data.writeInt(data);
this.proxy.sendRequest(IdlTestServiceProxy.COMMAND_TEST_INT_TRANSACTION, _data, _reply, _option).then(function(result) {
if (result.errCode == 0) {
let _errCode = result.reply.readInt();
if (_errCode != 0) {
let _returnValue = undefined;
callback(_errCode, _returnValue);
return;
}
let _returnValue = result.reply.readInt();
callback(_errCode, _returnValue);
} else {
console.log('sendRequest failed, errCode: ' + result.errCode);
}
})
}
testStringTransaction(data: string, callback: testStringTransactionCallback): void
{
let _option = new rpc.MessageOption();
let _data = new rpc.MessageParcel();
let _reply = new rpc.MessageParcel();
_data.writeString(data);
this.proxy.sendRequest(IdlTestServiceProxy.COMMAND_TEST_STRING_TRANSACTION, _data, _reply, _option).then(function(result) {
if (result.errCode == 0) {
let _errCode = result.reply.readInt();
callback(_errCode);
} else {
console.log('sendRequest failed, errCode: ' + result.errCode);
}
})
}
static readonly COMMAND_TEST_INT_TRANSACTION = 1;
static readonly COMMAND_TEST_STRING_TRANSACTION = 2;
private proxy
}
```
#### TS与C++实现互通
1. TS应用调用napi接口获取C++服务的远程对象
2. 构建TS Proxy对象,并把C++服务的远程对象传递给它
3. 此时开发者通过TS Proxy对象调用.idl声明的方法,实现TS Proxy与C++ Stub的互通,示例如下:
```ts
import IdlTestServiceProxy from './idl_test_service_proxy'
import nativeMgr from 'nativeManager';
function testIntTransactionCallback(errCode: number, returnValue: number)
{
console.log('errCode: ' + errCode + ' returnValue: ' + returnValue);
}
function testStringTransactionCallback(errCode: number)
{
console.log('errCode: ' + errCode);
}
function jsProxyTriggerCppStub()
{
let nativeObj = nativeMgr.GetNativeObject();
let tsProxy = new IdlTestServiceProxy(nativeObj);
// invoke testIntTransaction
tsProxy.testIntTransaction(10, testIntTransactionCallback);
// invoke testStringTransaction
tsProxy.testStringTransaction('test', testIntTransactionCallback);
}
```
...@@ -92,9 +92,6 @@ app对象包含应用全局配置信息,内部结构说明参见表2。 ...@@ -92,9 +92,6 @@ app对象包含应用全局配置信息,内部结构说明参见表2。
| vendor | 标识对应用开发厂商的描述。字符串长度不超过255字节。 | 字符串 | 可缺省,缺省值为空 | | vendor | 标识对应用开发厂商的描述。字符串长度不超过255字节。 | 字符串 | 可缺省,缺省值为空 |
| version | 标识应用的版本信息。参考表3。 | 对象 | 否 | | version | 标识应用的版本信息。参考表3。 | 对象 | 否 |
| apiVersion | 标识应用程序所依赖的OpenHarmony API版本。参考表4。 | 对象 | 可缺省,缺省值为空 | | apiVersion | 标识应用程序所依赖的OpenHarmony API版本。参考表4。 | 对象 | 可缺省,缺省值为空 |
| singleton | 标识应用是否开启单例模式,仅支持系统应用,三方应用配置不生效。如果配置为true,在多用户场景下,该应用仍然单实例运行,不会随用户切换而变动,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为false |
| removable | 标识应用是否可卸载,仅支持系统应用,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true |
| userDataClearable | 标识是否允许应用清除用户数据,仅支持系统应用,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true |
表3 version内部结构说明 表3 version内部结构说明
......
# appControl模块
本模块提供应用拦截能力。对应用设置处置状态后,应用会被禁止运行;用户点击桌面图标时,会根据应用的处置状态,跳转到对应的页面。本模块支持对应用的处置状态进行设置、获取、删除。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口为系统接口。
## 导入模块
``` ts
import appControl from '@ohos.bundle.appControl'
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want): Promise\<void>
以异步方法设置应用的处置状态。使用Promise异步回调。成功返回null,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用。
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 需要设置处置状态的应用的appId。<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| disposedWant | Want | 是 | 对应用的处置意图。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
var want = {bundleName: 'com.example.myapplication'};
try {
appControl.setDisposedStatus(appId, want)
.then(() => {
console.info('setDisposedStatus success');
}).catch((error) => {
console.error('setDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('setDisposedStatus failed ' + error.message);
}
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback\<void>): void;
以异步方法设置应用的处置状态。使用callback异步回调。成功返回null,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
| appId | string | 是 | 需要设置处置的应用的appId<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| disposedWant | Want | 是 | 对应用的处置意图。 |
| callback | AsyncCallback\<void> | 是 | 回调函数,当设置处置状态成功,err为undefined,否则为错误对象。 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
var want = {bundleName: 'com.example.myapplication'};
try {
appControl.setDisposedStatus(appId, want, (err, data) => {
if (err) {
console.error('setDisposedStatus failed ' + error.message);
return;
}
console.info('setDisposedStatus success');
});
} catch (error) {
console.error('setDisposedStatus failed ' + error.message);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string): Promise\<Want>;
以异步方法获取指定应用已设置的处置状态。使用Promise异步回调,成功返回应用的处置状态,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise\<Want> | Promise对象,返回应用的处置状态。 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
try {
appControl.getDisposedStatus(appId)
.then((data) => {
console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
}).catch((error) => {
console.error('getDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('getDisposedStatus failed ' + error.message);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string, callback: AsyncCallback\<Want>): void;
以异步方法获取指定应用的处置状态。使用callback异步回调,成功返回应用的处置状态,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| callback | AsyncCallback\<Want> | 是 | 回调函数。当获取应用的处置状态成功时,err为undefined,data为获取到的处置状态;否则为错误对象。 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
try {
appControl.getDisposedStatus(appId, (err, data) => {
if (err) {
console.error('getDisposedStatus failed ' + error.message);
return;
}
console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
});
} catch (error) {
console.error('getDisposedStatus failed ' + error.message);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string): Promise\<void>
以异步方法删除应用的处置状态。使用promise异步回调,成功返回null,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要删除处置状态的应用的appId<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 | |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise\<void> | Promise对象,无返回结果的Promise对象 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
try {
appControl.deleteDisposedStatus(appId)
.then(() => {
console.info('deleteDisposedStatus success');
}).catch((error) => {
console.error('deleteDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('deleteDisposedStatus failed ' + error.message);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string, callback: AsyncCallback\<void>) : void
以异步方法删除应用的处置状态。使用callback异步回调,成功返回null,失败返回对应错误信息。
**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
**系统API:** 此接口为系统接口,三方应用不支持调用
**参数:**
| 名称 | 类型 | 必填 | 描述 |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | 是 | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用的包名和签名信息决定,可以通过getBundleInfo接口获取。 |
| callback | AsyncCallback\<void> | 是 | 回调函数,当设置处置状态成功时,err返回undefined。否则回调函数返回具体错误对象。 |
**错误码**
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errcode-bundle.md)
| 错误码 | 错误信息 |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**示例:**
```ts
import appControl from '@ohos.bundle.appControl'
import bundleManager from '@ohos.bundle.bundleManager';
// 获取appId
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, BundleManager.BundleFlags.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
}, error => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
try {
appControl.deleteDisposedStatus(appId, (err, data) => {
if (err) {
console.error('deleteDisposedStatus failed ' + error.message);
return;
}
console.info('deleteDisposedStatus success');
});
} catch (error) {
console.error('deleteDisposedStatus failed ' + error.message);
}
```
# 输入监听 # 输入监听
InputMonitor模块提供了监听全局触摸事件的功能。 输入监听模块,提供了监听输入设备事件(当前支持触摸屏和鼠标)的能力。
> **说明:** > **说明:**
> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> >
> - 本模块接口均为系统接口。 > - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> - 本模块接口均为系统接口。
## 导入模块 ## 导入模块
...@@ -29,19 +29,19 @@ on(type: "touch", receiver: TouchEventReceiver): void ...@@ -29,19 +29,19 @@ on(type: "touch", receiver: TouchEventReceiver): void
**参数:** **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------- | | -------- | ---------------------------------------- | ---- | ------------------- |
| type | string | 是 | 监听输入事件类型,取值“touch”。 | | type | string | 是 | 输入设备事件类型,取值“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 触摸输入事件回调函数。 | | receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 回调函数,异步上报触摸屏输入事件。 |
**示例:** **示例:**
```js ```js
try { try {
inputMonitor.on("touch", (data)=> { inputMonitor.on("touch", (touchEvent) => {
console.log(`Monitor on TouchEvent success ${JSON.stringify(data)}`); console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false; return false;
}); });
} catch (error) { } catch (error) {
console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -58,19 +58,19 @@ on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void ...@@ -58,19 +58,19 @@ on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------- | ---- | ------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | 是 | 监听输入事件类型,取值“mouse”。 | | type | string | 是 | 输入设备事件类型,取值“mouse”。 |
| receiver | Callback&lt;MouseEvent&gt; | 是 | 鼠标输入事件回调函数。 | | receiver | Callback&lt;MouseEvent&gt; | 是 | 回调函数,异步上报鼠标输入事件。 |
**示例:** **示例:**
```js ```js
try { try {
inputMonitor.on("mouse", (data)=> { inputMonitor.on("mouse", (mouseEvent) => {
console.log(`Monitor on MouseEvent success ${JSON.stringify(data)}`); console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
return false; return false;
}); });
} catch (error) { } catch (error) {
console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -89,31 +89,36 @@ off(type: "touch", receiver?: TouchEventReceiver): void ...@@ -89,31 +89,36 @@ off(type: "touch", receiver?: TouchEventReceiver): void
**参数:** **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------- | | -------- | ---------------------------------------- | ---- | ------------------- |
| type | string | 是 | 监听输入事件类型,取值“touch”。 | | type | string | 是 | 输入设备事件类型,取值“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 触摸输入事件回调函数。 | | receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 需要取消监听的回调函数,若无此参数,则取消当前应用监听的所有回调函数。 |
**示例:** **示例:**
```js ```js
// 取消监听全局触屏事件 // 取消监听单个回调函数
try { callback: function(touchEvent) {
inputMonitor.off("touch"); console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
} catch (error) { return false;
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
console.log(`call success ${JSON.stringify(data)}`);
}, },
try { try {
inputMonitor.on("touch", this.callback); inputMonitor.on("touch", this.callback);
inputMonitor.off("touch", this.callback);
} catch (error) { } catch (error) {
console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// 取消监听所有回调函数
callback: function(touchEvent) {
console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
return false;
}, },
try { try {
inputMonitor.off("touch",this.callback); inputMonitor.on("touch", this.callback);
inputMonitor.off("touch");
} catch (error) { } catch (error) {
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -129,39 +134,40 @@ off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void ...@@ -129,39 +134,40 @@ off(type: "mouse", receiver?: Callback&lt;MouseEvent&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------- | ---- | ------------------- | | -------- | -------------------------- | ---- | ------------------- |
| type | string | 是 | 监听输入事件类型,取值“mouse”。 | | type | string | 是 | 输入设备事件类型,取值“mouse”。 |
| receiver | Callback&lt;MouseEvent&gt; | 否 | 鼠标输入事件回调函数。 | | receiver | Callback&lt;MouseEvent&gt; | 否 | 需要取消监听的回调函数,若无此参数,则取消当前应用监听的所有回调函数。 |
**示例:** **示例:**
```js ```js
// 取消监听全局鼠标事件 // 取消监听单个回调函数
try { callback: function(mouseEvent) {
inputMonitor.off("mouse"); console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
} catch (error) {
console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
console.log(`call success ${JSON.stringify(data)}`);
}, },
try { try {
inputMonitor.on("mouse", this.callback); inputMonitor.on("mouse", this.callback);
inputMonitor.off("mouse", this.callback);
} catch (error) { } catch (error) {
console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// 取消监听所有回调函数
callback: function(mouseEvent) {
console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
}, },
try { try {
inputMonitor.off("mouse", this.callback); inputMonitor.on("mouse", this.callback);
inputMonitor.off("mouse");
} catch (error) { } catch (error) {
console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## TouchEventReceiver ## TouchEventReceiver
触摸输入事件的回调函数。如果返回true,则触摸输入被监听器消耗,系统将执行关闭动作。 触摸输入事件的回调函数。
**需要权限:** ohos.permission.INPUT_MONITORING **需要权限:** ohos.permission.INPUT_MONITORING
...@@ -170,23 +176,25 @@ try { ...@@ -170,23 +176,25 @@ try {
**参数:** **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | | ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
| touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | 是 | 触摸输入事件回调函数,返回true表示输触事件被监听器消费,false表示输触事件未被监听器消费。 | | touchEvent | [TouchEvent](../arkui-js/js-components-common-events.md) | 是 | 触摸输入事件。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------- | ---------------------------------------- | | ------- | ---------------------------------------- |
| Boolean | 返回true表示触摸输入事件被监听器消费,false表示触摸输入事件未被监听器消费。 | | Boolean | 若返回true,本次触摸后续产生的事件不再分发到窗口;若返回false,本次触摸后续产生的事件还会分发到窗口。 |
**示例:** **示例:**
```js ```js
try { try {
inputMonitor.on("touch", (event) => { inputMonitor.on("touch", touchEvent => {
// 若返回true,表示本次操作后续所有事件不再分发到窗口,事件都由监听者消费。 if (touchEvent.touches.size() == 3) { // 当前有三个手指按下
return false; return true;
} else {
return false;
}
}); });
inputMonitor.off("touch");
} catch (error) { } catch (error) {
console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`); console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -148,7 +148,7 @@ import matrix4 from '@ohos.matrix4' ...@@ -148,7 +148,7 @@ import matrix4 from '@ohos.matrix4'
@Entry @Entry
@Component @Component
struct Test { struct Test {
private matrix1 = Matrix4.identity().translate({x:100}) private matrix1 = matrix4.identity().translate({x:100})
private matrix2 = this.matrix1.copy().scale({x:2}) private matrix2 = this.matrix1.copy().scale({x:2})
build() { build() {
......
...@@ -64,29 +64,57 @@ import tag from '@ohos.nfc.tag'; ...@@ -64,29 +64,57 @@ import tag from '@ohos.nfc.tag';
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
onCreate(want, launchParam) { onCreate(want, launchParam) {
// add other code here // add other code here...
// want is initialized by nfc service, contains tag info for this found tag // want is initialized by nfc service, contains tag info for this found tag
var tagInfo = tag.getTagInfo(want); var tagInfo;
if (tagInfo == undefined) { try {
tag.getTagInfo(want);
} catch (error) {
console.log("tag.getTagInfo catched error: " + error);
}
if (tagInfo == null || tagInfo == undefined) {
console.log("no TagInfo to be created, ignore it."); console.log("no TagInfo to be created, ignore it.");
return; return;
} }
// get the supported technologies for this found tag.
var isNfcATag = false; var isNfcATag = false;
var isIsoDepTag = false;
for (var i = 0; i < tagInfo.technology.length; i++) { for (var i = 0; i < tagInfo.technology.length; i++) {
if (tagInfo.technology[i] == tag.NFC_A) { if (tagInfo.technology[i] == tag.NFC_A) {
isNfcATag = true; isNfcATag = true;
break;
} }
// also check for technology: tag.NFC_B/NFC_F/NFC_V/ISO_DEP/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
if (tagInfo.technology[i] == tag.ISO_DEP) {
isIsoDepTag = true;
}
// also check for technology: tag.NFC_B/NFC_F/NFC_V/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
} }
// use NfcA APIs to access the found tag.
if (isNfcATag) { if (isNfcATag) {
var nfcA = tag.getNfcATag(taginfo); var nfcA;
try {
nfcA = tag.getNfcATag(taginfo);
} catch (error) {
console.log("tag.getNfcATag catched error: " + error);
}
// other code to read or write this found tag. // other code to read or write this found tag.
} }
// use the same code to handle for "NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef/MifareClassic/MifareUL/NdefFormatable", such as: // use getIsoDep APIs to access the found tag.
// var isoDep = tag.getIsoDepTag(taginfo); if (isIsoDepTag) {
var isoDep;
try {
isoDep = tag.getIsoDep(taginfo);
} catch (error) {
console.log("tag.getIsoDep catched error: " + error);
}
// other code to read or write this found tag.
}
// use the same code to handle for "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
} }
``` ```
...@@ -154,99 +182,135 @@ getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag) ...@@ -154,99 +182,135 @@ getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
| -------- | ---------------- | | -------- | ---------------- |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | NFC V类型Tag对象。 | | [NfcVTag](js-apis-nfctech.md#nfcvtag) | NFC V类型Tag对象。 |
## tag.getIsoDepTag<sup>9+</sup> ## tag.getIsoDep<sup>9+</sup>
getIsoDepTag(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 ) getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
获取IsoDep类型Tag对象,通过该对象可访问Iso Dep技术类型的Tag。 获取IsoDep类型Tag对象,通过该对象可访问支持IsoDep技术类型的Tag。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ---------- | ------------------| | ---------- | ------------------|
| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | Iso Dep类型Tag对象。 | | [IsoDepTag](js-apis-nfctech.md#isodeptag9) | IsoDep类型Tag对象,通过该对象访问IsoDep类型的相关接口。 |
## tag.getNdefTag<sup>9+</sup>
getNdefTag(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9) **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息|
| ------- | -------|
| 3100201 | Tag running state of service is abnormal. |
获取Ndef类型Tag对象,通过该对象可访问Ndef技术类型的Tag。 ## tag.getNdef<sup>9+</sup>
getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
**需要权限**:ohos.permission.NFC_TAG 获取NDEF类型Tag对象,通过该对象可访问支持NDEF技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ---------| -------------- | | ---------| -------------- |
| [NdefTag](js-apis-nfctech.md#ndeftag9) | Ndef类型Tag对象。| | [NdefTag](js-apis-nfctech.md#ndeftag9) | NDEF类型Tag对象,通过该对象访问NDEF类型的相关接口。|
## tag.getMifareClassicTag<sup>9+</sup> **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息|
| ------- | -------|
| 3100201 | Tag running state of service is abnormal. |
getMifareClassicTag(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) ## tag.getMifareClassic<sup>9+</sup>
获取Mifare Classic类型Tag对象,通过该对象访问Mifare Classic技术类型的Tag。 getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
**需要权限**:ohos.permission.NFC_TAG 获取MIFARE Classic类型Tag对象,通过该对象访问支持MIFARE Classic技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ----------------- | ------------------------| | ----------------- | ------------------------|
| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | Mifare Classic类型Tag对象。 | | [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | MIFARE Classic类型Tag对象,通过该对象访问MIFARE Classic类型的相关接口。 |
## tag.getMifareUltralightTag<sup>9+</sup> **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息|
| ------- | -------|
| 3100201 | Tag running state of service is abnormal. |
getMifareUltralightTag(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) ## tag.getMifareUltralight<sup>9+</sup>
获取Mifare Ultralight类型Tag对象,通过该对象可访问Mifare Ultralight技术类型的Tag。 getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
**需要权限**:ohos.permission.NFC_TAG 获取MIFARE Ultralight类型Tag对象,通过该对象可访问支持MIFARE Ultralight技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| -------------------- | ---------------------------| | -------------------- | ---------------------------|
| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | Mifare Ultralight类型Tag对象。 | | [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | MIFARE Ultralight类型Tag对象,通过该对象访问MIFARE Ultralight类型的相关接口。 |
## tag.getNdefFormatableTag<sup>9+</sup> **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息|
| ------- | -------|
| 3100201 | Tag running state of service is abnormal. |
getNdefFormatableTag(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9) ## tag.getNdefFormatable<sup>9+</sup>
获取Ndef Formatable类型Tag对象,通过该对象可访问Ndef Formatable技术类型的Tag。 getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
**需要权限**:ohos.permission.NFC_TAG 获取NDEF Formatable类型Tag对象,通过该对象可访问支持NDEF Formatable技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | Ndef Formatable类型Tag对象。 | | [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | NDEF Formatable类型Tag对象,通过该对象访问NDEF Formatable类型的相关接口。 |
**错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息|
| ------- | -------|
| 3100201 | Tag running state of service is abnormal. |
## tag.getTagInfo<sup>9+</sup> ## tag.getTagInfo<sup>9+</sup>
getTagInfo(want: Want): [TagInfo](#taginfo) getTagInfo(want: [Want](js-apis-application-Want.md#Want)): [TagInfo](#taginfo)
从Want中获取TagInfo,Want是被NFC服务初始化,包含了TagInfo所需的属性值。 从Want中获取TagInfo,Want是被NFC服务初始化,包含了TagInfo所需的属性值。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| want | [Want](js-apis-application-Want.md#Want) | 是 | 分发Ability时,在系统onCreate入口函数的参数中获取。 |
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 | | [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 |
...@@ -255,8 +319,6 @@ getTagInfo(want: Want): [TagInfo](#taginfo) ...@@ -255,8 +319,6 @@ getTagInfo(want: Want): [TagInfo](#taginfo)
NFC服务在读取到标签时给出的对象,通过改对象属性,应用知道该标签支持哪些技术类型,并使用匹配的技术类型来调用相关接口。 NFC服务在读取到标签时给出的对象,通过改对象属性,应用知道该标签支持哪些技术类型,并使用匹配的技术类型来调用相关接口。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** | | **参数名** | **类型** | **说明** |
...@@ -268,8 +330,6 @@ NFC服务在读取到标签时给出的对象,通过改对象属性,应用 ...@@ -268,8 +330,6 @@ NFC服务在读取到标签时给出的对象,通过改对象属性,应用
## NdefRecord<sup>9+</sup> ## NdefRecord<sup>9+</sup>
NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。 NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** | | **参数名** | **类型** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -281,8 +341,6 @@ NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDE ...@@ -281,8 +341,6 @@ NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDE
## 技术类型定义 ## 技术类型定义
NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。 NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -292,15 +350,13 @@ NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型 ...@@ -292,15 +350,13 @@ NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型
| NFC_F | 4 | NFC-F(JIS 6319-4)技术。| | NFC_F | 4 | NFC-F(JIS 6319-4)技术。|
| NFC_V | 5 | NFC-V(ISO 15693)技术。| | NFC_V | 5 | NFC-V(ISO 15693)技术。|
| NDEF | 6 | NDEF技术。| | NDEF | 6 | NDEF技术。|
| MIFARE_CLASSIC | 8 | Mifare Classic技术。| | MIFARE_CLASSIC | 8 | MIFARE Classic技术。|
| MIFARE_ULTRALIGHT | 9 | Mifare Utralight技术。| | MIFARE_ULTRALIGHT | 9 | MIFARE Utralight技术。|
| NDEF_FORMATABLE<sup>9+</sup> | 10 | 可以格式化的NDEF技术。| | NDEF_FORMATABLE<sup>9+</sup> | 10 | 可以格式化的NDEF技术。|
## TnfType<sup>9+</sup> ## TnfType<sup>9+</sup>
NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。 NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -315,8 +371,6 @@ NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFC ...@@ -315,8 +371,6 @@ NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFC
## NDEF Record RTD类型定义 ## NDEF Record RTD类型定义
NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。 NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -326,8 +380,6 @@ NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规 ...@@ -326,8 +380,6 @@ NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规
## NfcForumType<sup>9+</sup> ## NfcForumType<sup>9+</sup>
NFC Forum标准里面Tag类型的定义。 NFC Forum标准里面Tag类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -335,25 +387,21 @@ NFC Forum标准里面Tag类型的定义。 ...@@ -335,25 +387,21 @@ NFC Forum标准里面Tag类型的定义。
| NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 | | NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 |
| NFC_FORUM_TYPE_3 | 3 | NFC论坛类型3。 | | NFC_FORUM_TYPE_3 | 3 | NFC论坛类型3。 |
| NFC_FORUM_TYPE_4 | 4 | NFC论坛类型4。 | | NFC_FORUM_TYPE_4 | 4 | NFC论坛类型4。 |
| MIFARE_CLASSIC | 101 | Mifare Classic类型。 | | MIFARE_CLASSIC | 101 | MIFARE Classic类型。 |
## MifareClassicType<sup>9+</sup> ## MifareClassicType<sup>9+</sup>
MifareClassic标签类型的定义。 MIFARE Classic标签类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| TYPE_UNKNOWN | -1 | 未知Mifare类型。 | | TYPE_UNKNOWN | 0 | 未知MIFARE类型。 |
| TYPE_CLASSIC | 0 | Mifare Classic类型。| | TYPE_CLASSIC | 1 | MIFARE Classic类型。|
| TYPE_PLUS | 1 | Mifare Plus类型。| | TYPE_PLUS | 2 | MIFARE Plus类型。|
| TYPE_PRO | 2 | Mifare Pro类型。 | | TYPE_PRO | 3 | MIFARE Pro类型。 |
## MifareClassicSize<sup>9+</sup> ## MifareClassicSize<sup>9+</sup>
MifareClassic标签存储大小的定义。 MIFARE Classic标签存储大小的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
...@@ -363,15 +411,13 @@ MifareClassic标签存储大小的定义。 ...@@ -363,15 +411,13 @@ MifareClassic标签存储大小的定义。
| MC_SIZE_2K | 2048 | 每个标签32个扇区,每个扇区4个块。 | | MC_SIZE_2K | 2048 | 每个标签32个扇区,每个扇区4个块。 |
| MC_SIZE_4K | 4096 | 每个标签40个扇区,每个扇区4个块。| | MC_SIZE_4K | 4096 | 每个标签40个扇区,每个扇区4个块。|
### MifareUltralightType<sup>9+</sup> ## MifareUltralightType<sup>9+</sup>
MifareUltralight标签类型的定义。 MIFARE Ultralight标签类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| TYPE_UNKOWN | -1 | 未知的 Mifare 类型。 | | TYPE_UNKOWN | 0 | 未知的 MIFARE 类型。 |
| TYPE_ULTRALIGHT | 1 | Mifare Ultralight类型。| | TYPE_ULTRALIGHT | 1 | MIFARE Ultralight类型。|
| TYPE_ULTRALIGHT_C | 2 | Mifare UltralightC 类型。 | | TYPE_ULTRALIGHT_C | 2 | MIFARE UltralightC 类型。 |
<!--no_check--> <!--no_check-->
\ No newline at end of file
...@@ -13,64 +13,82 @@ import tag from '@ohos.nfc.tag'; ...@@ -13,64 +13,82 @@ import tag from '@ohos.nfc.tag';
## tagSession ## tagSession
tagSession是所有[Nfc tag 技术类型](js-apis-nfctech.md)的基类, 提供建立连接和发送数据等共同接口。 tagSession是所有[NFC Tag技术类型](js-apis-nfctech.md)的基类, 提供建立连接和发送数据等共同接口。
需要通过其子类来访问以下接口。在下面的示例中 统一用 getXXTag表示获取子类实例的方法。 需要通过其子类来访问以下接口。在下面的示例中 统一用 getXXX()表示获取子类实例的方法。
具体使用时,请根据实际采用的Nfc tag技术,选择对应的方法,具体请参见[nfcTag](js-apis-nfcTag.md)文档。 具体使用时,请根据实际采用的Nfc tag技术,选择对应的方法,具体请参见[nfcTag](js-apis-nfcTag.md)文档。
### tagSession.connectTag ### tagSession.getTagInfo
connectTag(): boolean;
和标签建立连接; getTagInfo(): tag.TagInfo
在从标签读取数据或将数据写入标签之前,必须调用此方法 获取该Tag被分发时,NFC服务所提供的Tag数据对象
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 连接建立成功返回 true,失败返回false。 | | TagInfo | NFC服务所提供的Tag数据对象。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
let isNfcConnected = tag.getXXXTag(taginfo).connectTag(); // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
console.log("isNfcConnected:" +isNfcConnected);
let tagInfo = tag.getXXX(tagInfo).getTagInfo();
console.log("tag tagInfo: " + tagInfo);
``` ```
### tagSession.reset() ### tagSession.connectTag
reset(): void connectTag(): boolean;
重置与标签的连接,并恢复将数据写入标签的默认超时时间 和标签建立连接。在从标签读取数据或将数据写入标签之前,必须调用此方法
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 方法执行成功返回 true,失败返回false。 | | boolean | 连接建立成功返回true,失败返回false。 |
**示例:** **示例:**
```js
import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let connectStatus = tag.getXXX(tagInfo).connectTag();
console.log("connectStatus: " + connectStatus);
```
### tagSession.reset()
reset(): void
重置与标签的连接。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
**示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
let reset = tag.getXXXTag(taginfo).reset(); // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
console.log("reset:" +reset);
tag.getXXX(tagInfo).reset();
``` ```
### tagSession.isTagConnected ### tagSession.isTagConnected
...@@ -84,19 +102,19 @@ isTagConnected(): boolean ...@@ -84,19 +102,19 @@ isTagConnected(): boolean
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 已建立连接返回 true,未建立连接返回false。 | | boolean | 已建立连接返回 true,未建立连接返回false。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
let isTagConnected = tag.getXXXTag(taginfo).isTagConnected(); // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
console.log("isTagConnected:" +isTagConnected);
let isTagConnected = tag.getXXX(tagInfo).isTagConnected();
console.log("isTagConnected: " + isTagConnected);
``` ```
### tagSession.getMaxSendLength ### tagSession.getMaxSendLength
...@@ -110,17 +128,160 @@ getMaxSendLength(): number ...@@ -110,17 +128,160 @@ getMaxSendLength(): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
| number | 可以发送到标签的最大数据长度,非负数。 |
**示例:**
```js
import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let maxSendLen = tag.getXXX(tagInfo).getMaxSendLength();
console.log("tag maxSendLen: " + maxSendLen);
```
### tagSession.getSendDataTimeout
getSendDataTimeout(): number
查询发送数据到Tag的等待超时时间,单位是毫秒。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
**返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 可以发送到标签的最大数据长度。 | | number | 发送数据到Tag的等待超时时间,单位是毫秒,非负数。 |
**示例:** **示例:**
```js
import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let sendDataTimeout = tag.getXXX(tagInfo).getSendDataTimeout();
console.log("tag sendDataTimeout: " + sendDataTimeout);
```
### tagSession.setSendDataTimeout
setSendDataTimeout(timeout: number): boolean
查询发送数据到Tag的等待超时时间,单位是毫秒。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| timeout | number | 是 | 超时时间,单位毫秒,非负值。 |
**返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
| boolean | 设置超时时间成功返回true,设置失败返回false。 |
**示例:**
```js
import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let timeoutMs = 700; // change it to be correct.
let setStatus = tag.getXXX(tagInfo).setSendDataTimeout(timeoutMs);
console.log("tag setSendDataTimeout setStatus: " + setStatus);
```
### tagSession.sendData
sendData(data: number[]): Promise<number[]>
发送指令到Tag上,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 |
**返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
| Promise<number[]> | 对端Tag对指令的响应数据。每个number十六进制表示,范围是0x00~0xFF。|
**示例:**
```js
import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
// connect the tag at first if not connected.
if (!tag.getXXX(tagInfo).isTagConnected()) {
if (!tag.getXXX(tagInfo).connectTag()) {
console.log("tagSession connectTag failed.");
return;
}
}
let cmdData = [0x01, 0x02, ...]; // change the raw data to be correct.
tag.getXXX(tagInfo).sendData(cmdData).then((response) => {
console.log("tagSession sendData Promise response: " + response);
}).catch((err)=> {
console.log("tagSession sendData Promise err: " + err);
});
```
### tagSession.sendData
sendData(data: number[], callback: AsyncCallback<number[]>): void
发送指令到Tag上,使用AsyncCallback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 |
| callback | AsyncCallback<number[]> | 是 | 回调函数,返回响应数据。每个number十六进制表示,范围是0x00~0xFF。 |
**示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
let mazSendLen = tag.getXXXTag(taginfo).getMaxSendLength(); // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
console.log("mazSendLen:" +mazSendLen);
// connect the tag at first if not connected.
if (!tag.getXXX(tagInfo).isTagConnected()) {
if (!tag.getXXX(tagInfo).connectTag()) {
console.log("tagSession connectTag failed.");
return;
}
}
let cmdData = [0x01, 0x02, ...]; // change the raw data to be correct.
tag.getXXX(tagInfo).sendData(cmdData, (err, response)=> {
if (err) {
console.log("tagSession sendData AsyncCallback err: " + err);
} else {
console.log("tagSession sendData AsyncCallback response: " + response);
}
});
``` ```
...@@ -29,7 +29,7 @@ export default class UserTestRunner implements TestRunner { ...@@ -29,7 +29,7 @@ export default class UserTestRunner implements TestRunner {
onPrepare() { onPrepare() {
console.log("Trigger onPrepare") console.log("Trigger onPrepare")
} }
onRun(){} onRun() {}
}; };
``` ```
...@@ -47,9 +47,9 @@ onRun(): void ...@@ -47,9 +47,9 @@ onRun(): void
```js ```js
export default class UserTestRunner implements TestRunner { export default class UserTestRunner implements TestRunner {
onPrepare() { onPrepare() {}
console.log("Trigger onRun") onRun() {
console.log("Trigger onRun")
} }
onRun(){}
}; };
``` ```
...@@ -777,10 +777,10 @@ on(type: 'systemBarTintChange', callback: Callback&lt;SystemBarTintState&gt;): v ...@@ -777,10 +777,10 @@ on(type: 'systemBarTintChange', callback: Callback&lt;SystemBarTintState&gt;): v
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | | type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 | | callback | Callback&lt;[SystemBarTintState](#systembartintstate8)&gt; | 是 | 回调函数。返回当前的状态栏、导航栏信息集合。 |
**示例:** **示例:**
...@@ -806,10 +806,10 @@ off(type: 'systemBarTintChange', callback?: Callback&lt;SystemBarTintState &gt;) ...@@ -806,10 +806,10 @@ off(type: 'systemBarTintChange', callback?: Callback&lt;SystemBarTintState &gt;)
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 | | type | string | 是 | 监听事件,固定为'systemBarTintChange',即导航栏、状态栏属性变化事件。 |
| callback | Callback&lt;[SystemBarTintState](#systembartintstate)&gt; | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。 | | callback | Callback&lt;[SystemBarTintState](#systembartintstate8)&gt; | 否 | 回调函数。返回当前的状态栏、导航栏信息集合。 |
**示例:** **示例:**
...@@ -1638,6 +1638,12 @@ resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -1638,6 +1638,12 @@ resize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): void
改变当前窗口大小,使用callback异步回调。 改变当前窗口大小,使用callback异步回调。
应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。
系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。
设置的宽度与高度受到此约束限制。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core **系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:** **参数:**
...@@ -1679,6 +1685,12 @@ resize(width: number, height: number): Promise&lt;void&gt; ...@@ -1679,6 +1685,12 @@ resize(width: number, height: number): Promise&lt;void&gt;
改变当前窗口大小,使用Promise异步回调。 改变当前窗口大小,使用Promise异步回调。
应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。
系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。
设置的宽度与高度受到此约束限制。
**系统能力:** SystemCapability.WindowManager.WindowManager.Core **系统能力:** SystemCapability.WindowManager.WindowManager.Core
**参数:** **参数:**
...@@ -4369,6 +4381,12 @@ resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): v ...@@ -4369,6 +4381,12 @@ resetSize(width: number, height: number, callback: AsyncCallback&lt;void&gt;): v
改变当前窗口大小,使用callback异步回调。 改变当前窗口大小,使用callback异步回调。
应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。
系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。
设置的宽度与高度受到此约束限制。
> **说明:** > **说明:**
> >
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。 > 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9)。
...@@ -4401,6 +4419,12 @@ resetSize(width: number, height: number): Promise&lt;void&gt; ...@@ -4401,6 +4419,12 @@ resetSize(width: number, height: number): Promise&lt;void&gt;
改变当前窗口大小,使用Promise异步回调。 改变当前窗口大小,使用Promise异步回调。
应用主窗口与子窗口存在大小限制,宽度范围:[320, 2560],高度范围:[240, 2560],单位为vp。
系统窗口存在大小限制,宽度范围:[0, 2560],高度范围:[0, 2560],单位为vp。
设置的宽度与高度受到此约束限制。
> **说明:** > **说明:**
> >
> 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。 > 从 API version 7开始支持,从API version 9开始废弃,推荐使用[resize()](#resize9-1)。
......
# slider # slider
> **说明:** > **说明:**
>
> 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
滑动条组件,用来快速调节设置值,如音量、亮度等。 滑动条组件,用来快速调节设置值,如音量、亮度等。
...@@ -94,7 +95,7 @@ export default { ...@@ -94,7 +95,7 @@ export default {
} else if (e.mode == "end") { } else if (e.mode == "end") {
this.value = e.value; this.value = e.value;
this.endValue = e.value; this.endValue = e.value;
} else if (e.mode == "click) { } else if (e.mode == "click") {
this.value = e.value; this.value = e.value;
this.currentValue = e.value; this.currentValue = e.value;
} }
......
...@@ -320,7 +320,7 @@ struct ImageExample3 { ...@@ -320,7 +320,7 @@ struct ImageExample3 {
.onError(() => { .onError(() => {
console.log('load image fail') console.log('load image fail')
}) })
.overlay('\nwidth: ' + String(this.width) + ' height: ' + String(this.height), { .overlay('\nwidth: ' + String(this.widthValue) + ' height: ' + String(this.heightValue), {
align: Alignment.Bottom, align: Alignment.Bottom,
offset: { x: 0, y: 20 } offset: { x: 0, y: 20 }
}) })
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
| ---------- | ------------------------------------------ | ---- | ----------- | ------------------------------------------- | | ---------- | ------------------------------------------ | ---- | ----------- | ------------------------------------------- |
| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.White | 文本颜色。 | | color | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.White | 文本颜色。 |
| fontSize | number&nbsp;\|&nbsp;string | 否 | 10 | 文本大小,单位vp。 | | fontSize | number&nbsp;\|&nbsp;string | 否 | 10 | 文本大小,单位vp。 |
| badgeSize | number&nbsp;\|&nbsp;string | 否 | 16 | Badge的大小,单位vp。不支持百分比形式设置。 | | badgeSize | number&nbsp;\|&nbsp;string | 否 | 16 | Badge的大小,单位vp。不支持百分比形式设置。当设置为非法值时,按照默认值处理。 |
| badgeColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.Red | Badge的颜色。 | | badgeColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.Red | Badge的颜色。 |
## 示例 ## 示例
......
...@@ -25,7 +25,7 @@ WaterFlow(options?: {footer?: CustomBuilder, scroller?: Scroller}) ...@@ -25,7 +25,7 @@ WaterFlow(options?: {footer?: CustomBuilder, scroller?: Scroller})
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| ---------- | ----------------------------------------------- | ------ | -------------------------------------------- | | ---------- | ----------------------------------------------- | ------ | -------------------------------------------- |
| footer | [CustomBuilder](ts-types.md#custombuilder8) | 否 | 设置WaterFlow尾部组件。 | | footer | [CustomBuilder](ts-types.md#custombuilder8) | 否 | 设置WaterFlow尾部组件。 |
| scroller | [Scroller](ts-container-scroll.md#scroller) | 否 | 可滚动组件的控制器,与可滚动组件绑定。 | | scroller | [Scroller](ts-container-scroll.md#scroller) | 否 | 可滚动组件的控制器,与可滚动组件绑定。<br/>目前瀑布流仅支持Scroller组件的scrollToIndex接口。 |
## 属性 ## 属性
...@@ -40,8 +40,21 @@ WaterFlow(options?: {footer?: CustomBuilder, scroller?: Scroller}) ...@@ -40,8 +40,21 @@ WaterFlow(options?: {footer?: CustomBuilder, scroller?: Scroller})
| itemConstraintSize | [ConstraintSizeOptions](ts-types.md#constraintsizeoptions) | 设置约束尺寸,子组件布局时,进行尺寸范围限制。 | | itemConstraintSize | [ConstraintSizeOptions](ts-types.md#constraintsizeoptions) | 设置约束尺寸,子组件布局时,进行尺寸范围限制。 |
| columnsGap | Length |设置列与列的间距。 <br>默认值:0| | columnsGap | Length |设置列与列的间距。 <br>默认值:0|
| rowsGap | Length |设置行与行的间距。<br> 默认值:0| | rowsGap | Length |设置行与行的间距。<br> 默认值:0|
| layoutDirection | [FlexDirection](ts-appendix-enums.md#flexdirection) |设置布局的主轴方向。| | layoutDirection | [FlexDirection](ts-appendix-enums.md#flexdirection) |设置布局的主轴方向。<br/>默认值:FlexDirection.Column|
layoutDirection优先级高于rowsTemplate和columnsTemplate。根据layoutDirection设置情况,分为以下三种设置模式:
- layoutDirection设置纵向布局(FlexDirection.Column 或 FlexDirection.ColumnReverse)
此时columnsTemplate有效(如果未设置,取默认值)。例如columnsTemplate设置为"1fr 1fr"、rowsTemplate设置为"1fr 1fr 1fr"时,瀑布流组件纵向布局,辅轴均分成横向2列。
- layoutDirection设置横向布局(FlexDirection.Row 或 FlexDirection.RowReverse)
此时rowsTemplate有效(如果未设置,取默认值)。例如columnsTemplate设置为"1fr 1fr"、rowsTemplate设置为"1fr 1fr 1fr"时,瀑布流组件横向布局,辅轴均分成纵向3列。
- layoutDirection未设置布局方向
布局方向为layoutDirection的默认值:FlexDirection.Column,此时columnsTemplate有效。例如columnsTemplate设置为"1fr 1fr"、rowsTemplate设置为"1fr 1fr 1fr"时,瀑布流组件纵向布局,辅轴均分成横向2列。
## 事件 ## 事件
...@@ -79,8 +92,8 @@ export class WaterFlowDataSource implements IDataSource { ...@@ -79,8 +92,8 @@ export class WaterFlowDataSource implements IDataSource {
private listeners: DataChangeListener[] = [] private listeners: DataChangeListener[] = []
constructor() { constructor() {
for (let i = 0; i <= 100; i++) { for (let i = 0; i < 100; i++) {
this.dataArray.push(i); this.dataArray.push(i)
} }
} }
...@@ -138,7 +151,7 @@ export class WaterFlowDataSource implements IDataSource { ...@@ -138,7 +151,7 @@ export class WaterFlowDataSource implements IDataSource {
// 注销改变数据的控制器 // 注销改变数据的控制器
unregisterDataChangeListener(listener: DataChangeListener): void { unregisterDataChangeListener(listener: DataChangeListener): void {
const pos = this.listeners.indexOf(listener); const pos = this.listeners.indexOf(listener)
if (pos >= 0) { if (pos >= 0) {
this.listeners.splice(pos, 1) this.listeners.splice(pos, 1)
} }
...@@ -182,9 +195,9 @@ export class WaterFlowDataSource implements IDataSource { ...@@ -182,9 +195,9 @@ export class WaterFlowDataSource implements IDataSource {
// 重新加载数据 // 重新加载数据
public Reload(): void { public Reload(): void {
this.dataArray.splice(1, 1); this.dataArray.splice(1, 1)
this.dataArray.splice(3, 2); this.dataArray.splice(3, 2)
this.notifyDataReload(); this.notifyDataReload()
} }
} }
``` ```
...@@ -200,8 +213,10 @@ struct WaterflowDemo { ...@@ -200,8 +213,10 @@ struct WaterflowDemo {
@State maxSize: number = 100 @State maxSize: number = 100
@State fontSize: number = 24 @State fontSize: number = 24
@State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F] @State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F]
scroller: Scroller = new Scroller(); scroller: Scroller = new Scroller()
datasource: WaterFlowDataSource = new WaterFlowDataSource(); datasource: WaterFlowDataSource = new WaterFlowDataSource()
private itemWidthArray: number[] = []
private itemHeightArray: number[] = []
// 计算flow item宽/高 // 计算flow item宽/高
getSize() { getSize() {
...@@ -209,6 +224,18 @@ struct WaterflowDemo { ...@@ -209,6 +224,18 @@ struct WaterflowDemo {
return (ret > this.minSize ? ret : this.minSize) return (ret > this.minSize ? ret : this.minSize)
} }
// 保存flow item宽/高
getItemSizeArray() {
for (let i = 0; i < 100; i++) {
this.itemWidthArray.push(this.getSize())
this.itemHeightArray.push(this.getSize())
}
}
aboutToAppear() {
this.getItemSizeArray()
}
@Builder itemFoot() { @Builder itemFoot() {
Column() { Column() {
Text(`Footer`) Text(`Footer`)
...@@ -232,8 +259,8 @@ struct WaterflowDemo { ...@@ -232,8 +259,8 @@ struct WaterflowDemo {
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
} }
} }
.width(this.getSize()) .width(this.itemWidthtArray[item1])
.height(this.getSize()) .height(this.itemHeightArray[item1])
.backgroundColor(this.colors[item % 5]) .backgroundColor(this.colors[item % 5])
}, item => item) }, item => item)
} }
...@@ -261,4 +288,4 @@ struct WaterflowDemo { ...@@ -261,4 +288,4 @@ struct WaterflowDemo {
} }
``` ```
![zh-cn_image_WaterFlow.gif](figures/waterflow.gif) ![zh-cn_image_WaterFlow.gif](figures/waterflow.gif)
\ No newline at end of file
...@@ -47,7 +47,7 @@ SetAndLink\<T>(propName: string, defaultValue: T): SubscribedAbstractProperty\<T ...@@ -47,7 +47,7 @@ SetAndLink\<T>(propName: string, defaultValue: T): SubscribedAbstractProperty\<T
| 类型 | 描述 | | 类型 | 描述 |
| ----- | ------------------------------------------------------------ | | ----- | ------------------------------------------------------------ |
| @Link | 与Link接口类似,如果当前的key保存于LocalStorage,返回该key值对应的value值。如果该key值未被创建,则创建一个对应的defaultValue的Link返回。 | | @Link | 与Link接口类似,如果当前的key保存于AppStorage,返回该key值对应的value值。如果该key值未被创建,则创建一个对应的defaultValue的Link返回。 |
```ts ```ts
let simple = AppStorage.SetAndLink('simpleProp', 121) let simple = AppStorage.SetAndLink('simpleProp', 121)
...@@ -92,7 +92,7 @@ SetAndProp\<S>(propName: string, defaultValue: S): SubscribedAbstractProperty\<S ...@@ -92,7 +92,7 @@ SetAndProp\<S>(propName: string, defaultValue: S): SubscribedAbstractProperty\<S
| 类型 | 描述 | | 类型 | 描述 |
| ----- | ------------------------------------------------------------ | | ----- | ------------------------------------------------------------ |
| @Prop | 如果当前的key保存与LocalStorage,返回该key值对应的value值。如果该key值未被创建,则创建一个对应的defaultValue的Prop返回。 | | @Prop | 如果当前的key保存与AppStorage,返回该key值对应的value值。如果该key值未被创建,则创建一个对应的defaultValue的Prop返回。 |
```ts ```ts
let simple = AppStorage.SetAndProp('simpleProp', 121) let simple = AppStorage.SetAndProp('simpleProp', 121)
...@@ -182,7 +182,7 @@ SetOrCreate\<T>(propName: string, newValue: T): void ...@@ -182,7 +182,7 @@ SetOrCreate\<T>(propName: string, newValue: T): void
| 类型 | 描述 | | 类型 | 描述 |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ |
| boolean | 如果已存在与给定键名字相同的属性,更新其值且返回true。如果不存在具有给定名称的属性,在LocalStorage中创建具有给定默认值的新属性,默认值必须是T类型。不允许undefined 或 null 返回true。 | | boolean | 如果已存在与给定键名字相同的属性,更新其值且返回true。如果不存在具有给定名称的属性,在AppStorage中创建具有给定默认值的新属性,默认值必须是T类型。不允许undefined 或 null 返回true。 |
```ts ```ts
let simple = AppStorage.SetOrCreate('simpleProp', 121) let simple = AppStorage.SetOrCreate('simpleProp', 121)
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
> **说明:** > **说明:**
> >
>从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
>
> 此接口为系统接口。
## 属性 ## 属性
......
# NFC错误码
## 3100101
**错误信息**
NFC opening or closing state is abnormal in service.
**错误描述**
NFC服务内部执行NFC打开或关闭异常。
**可能原因**
和NFC服务建立通信异常。
**处理步骤**
重新执行打开或关闭NFC。
## 3100201
**错误信息**
Tag running state is abnormal in service.
**错误描述**
NFC服务执行Tag业务逻辑遇到错误。
**可能原因**
1. Tag参数值和实际调用函数要求不匹配。
2. Tag操作时,NFC状态是关闭的。
3. Tag操作前,已经处在断开状态。
4. Tag芯片返回错误状态或响应超时。
5. 和NFC服务没有建立绑定关系,无法调用接口。
**处理步骤**
1. 检查NFC参数是否和所调用接口匹配。
2. 打开设备NFC。
3. 先调用连接,再执行读写操作。
4. 重新触碰读取卡片。
5. 退出应用后,重新读取卡片。
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
- 语法 - 语法
- [HML语法参考](js-service-widget-syntax-hml.md) - [HML语法参考](js-service-widget-syntax-hml.md)
- [CSS语法参考](js-service-widget-syntax-css.md) - [CSS语法参考](js-service-widget-syntax-css.md)
- [配置数据和事件](js-service-widget-configuration.md)
- [多语言支持](js-service-widget-multiple-languages.md) - [多语言支持](js-service-widget-multiple-languages.md)
- [低版本兼容](js-service-widget-version-compatibility.md) - [版本兼容适配](js-service-widget-version-compatibility.md)
- [设置主题样式](js-service-widget-theme.md)
- 组件 - 组件
- 通用 - 通用
- [通用属性](js-service-widget-common-attributes.md) - [通用属性](js-service-widget-common-attributes.md)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
- [无障碍](js-service-widget-common-accessibility.md) - [无障碍](js-service-widget-common-accessibility.md)
- [原子布局](js-service-widget-common-atomic-layout.md) - [原子布局](js-service-widget-common-atomic-layout.md)
- 容器组件 - 容器组件
- [badge](js-service-widget-container-badge.md)
- [div](js-service-widget-container-div.md) - [div](js-service-widget-container-div.md)
- [list](js-service-widget-container-list.md) - [list](js-service-widget-container-list.md)
- [list-item](js-service-widget-container-list-item.md) - [list-item](js-service-widget-container-list-item.md)
...@@ -35,8 +36,5 @@ ...@@ -35,8 +36,5 @@
- [progress](js-service-widget-basic-progress.md) - [progress](js-service-widget-basic-progress.md)
- [span](js-service-widget-basic-span.md) - [span](js-service-widget-basic-span.md)
- [text](js-service-widget-basic-text.md) - [text](js-service-widget-basic-text.md)
- 自定义组件 - [自定义组件使用说明](js-service-widget-custom-basic-usage.md)
- [自定义组件基本用法](js-service-widget-custom-basic-usage.md)
- [自定义事件](js-service-widget-custom-events.md)
- [Props](js-service-widget-custom-props.md)
- [数据类型说明](js-service-widget-appendix-types.md) - [数据类型说明](js-service-widget-appendix-types.md)
# 媒体查询 # 媒体查询
媒体查询(Media Query)在移动设备上应用十分广泛,开发者经常需要根据设备的大致类型或者特定的特征和设备参数(例如屏幕分辨率)来修改应用的样式。为此媒体查询提供了如下功能: 媒体查询(MediaQuery)在移动设备上应用十分广泛,开发者经常需要根据设备的大致类型或者特定的特征和设备参数(例如屏幕分辨率)来修改应用的样式。为此媒体查询提供了如下功能:
1. 针对设备和应用的属性信息,可以设计出相匹配的布局样式。 1. 针对设备和应用的属性信息,可以设计出相匹配的布局样式。
......
# 配置数据和事件
卡片使用json文件配置卡片使用的变量和事件,变量的声明在data字段下,事件的声明在actions字段下。
示例:
```json
{
"data": {
"temperature": "35°C",
"city": "hangzhou"
},
"actions": {
"routerEventName": {
"action": "router",
"abilityName": "com.example.myapplication.FormAbility",
"params": {
"message": "weather",
"temperature": "{{temperature}}"
}
},
"messageEventName": {
"action": "message",
"params": {
"message": "weather update"
}
}
}
}
```
可参考示例:[input](./js-service-widget-basic-input.md)[list](js-service-widget-container-list.md)等组件中的用法。
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册