Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
408b7db1
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
408b7db1
编写于
8月 22, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 22, 2023
浏览文件
操作
浏览文件
下载
差异文件
!22456 资源管理新增同步接口描述,规划接口排版
Merge pull request !22456 from zt147369/master
上级
b329af8f
33be354d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1687 addition
and
1336 deletion
+1687
-1336
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
...pplication-dev/reference/apis/js-apis-resource-manager.md
+1687
-1336
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
浏览文件 @
408b7db1
...
@@ -22,10 +22,10 @@ Stage模型下Context的引用方法请参考[Stage模型的Context详细介绍]
...
@@ -22,10 +22,10 @@ Stage模型下Context的引用方法请参考[Stage模型的Context详细介绍]
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
export
default
class
EntryAbility
extends
UIAbility
{
export
default
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
)
{
onWindowStageCreate
(
windowStage
)
{
let
context
=
this
.
context
;
let
context
=
this
.
context
;
let
resourceManager
=
context
.
resourceManager
;
let
resourceManager
=
context
.
resourceManager
;
}
}
}
}
```
```
...
@@ -48,17 +48,17 @@ getResourceManager(callback: AsyncCallback<ResourceManager>): void
...
@@ -48,17 +48,17 @@ getResourceManager(callback: AsyncCallback<ResourceManager>): void
**示例:**
**示例:**
```
js
```
js
resourceManager
.
getResourceManager
((
error
,
mgr
)
=>
{
resourceManager
.
getResourceManager
((
error
,
mgr
)
=>
{
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
return
;
}
mgr
.
getStringValue
(
0x1000000
,
(
error
,
value
)
=>
{
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
console
.
log
(
"
error is
"
+
error
);
return
;
}
else
{
let
str
=
value
;
}
}
mgr
.
getStringValue
(
0x1000000
,
(
error
,
value
)
=>
{
});
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
str
=
value
;
}
});
});
});
```
```
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
...
@@ -107,15 +107,15 @@ getResourceManager(): Promise<ResourceManager>
...
@@ -107,15 +107,15 @@ getResourceManager(): Promise<ResourceManager>
**示例:**
**示例:**
```
js
```
js
resourceManager
.
getResourceManager
().
then
(
mgr
=>
{
resourceManager
.
getResourceManager
().
then
(
mgr
=>
{
mgr
.
getStringValue
(
0x1000000
,
(
error
,
value
)
=>
{
mgr
.
getStringValue
(
0x1000000
,
(
error
,
value
)
=>
{
if
(
error
!=
null
)
{
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
console
.
log
(
"
error is
"
+
error
);
}
else
{
}
else
{
let
str
=
value
;
let
str
=
value
;
}
}
});
});
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
error is
"
+
error
);
console
.
log
(
"
error is
"
+
error
);
});
});
```
```
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
...
@@ -150,7 +150,6 @@ getResourceManager(bundleName: string): Promise<ResourceManager>
...
@@ -150,7 +150,6 @@ getResourceManager(bundleName: string): Promise<ResourceManager>
});
});
```
```
## resourceManager.getSystemResourceManager<sup>10+</sup>
## resourceManager.getSystemResourceManager<sup>10+</sup>
getSystemResourceManager(): ResourceManager
getSystemResourceManager(): ResourceManager
...
@@ -177,16 +176,16 @@ getSystemResourceManager(): ResourceManager
...
@@ -177,16 +176,16 @@ getSystemResourceManager(): ResourceManager
```
js
```
js
import
resourceManager
from
'
@ohos.resourceManager
'
;
import
resourceManager
from
'
@ohos.resourceManager
'
;
try
{
try
{
let
systemResourceManager
=
resourceManager
.
getSystemResourceManager
();
let
systemResourceManager
=
resourceManager
.
getSystemResourceManager
();
systemResourceManager
.
getStringValue
(
$r
(
'
sys.string.ohos_lab_vibrate
'
).
id
).
then
(
value
=>
{
systemResourceManager
.
getStringValue
(
$r
(
'
sys.string.ohos_lab_vibrate
'
).
id
).
then
(
value
=>
{
let
str
=
value
;
let
str
=
value
;
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
systemResourceManager getStringValue promise error is
"
+
error
);
console
.
log
(
"
systemResourceManager getStringValue promise error is
"
+
error
);
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`systemResourceManager getStringValue failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console
.
error
(
`systemResourceManager getStringValue failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
}
```
```
...
@@ -301,20 +300,25 @@ try {
...
@@ -301,20 +300,25 @@ try {
>
>
> - 资源文件在工程的resources目录中定义,id可通过$r(资源地址).id的方式获取,例如$r('app.string.test').id。
> - 资源文件在工程的resources目录中定义,id可通过$r(资源地址).id的方式获取,例如$r('app.string.test').id。
### getString
Value
<sup>9+</sup>
### getString
Sync
<sup>9+</sup>
getString
Value(resId: number, callback: AsyncCallback
<
string
>
): void
getString
Sync(resId: number): string
用户获取指定资源ID对应的字符串,使用
callback形
式返回字符串。
用户获取指定资源ID对应的字符串,使用
同步方
式返回字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**系统能力**
:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的字符串 |
**返回值:**
| 类型 | 说明 |
| ------ | ----------- |
| string | 资源ID值对应的字符串 |
**错误码:**
**错误码:**
...
@@ -322,31 +326,24 @@ getStringValue(resId: number, callback: AsyncCallback<string>): void
...
@@ -322,31 +326,24 @@ getStringValue(resId: number, callback: AsyncCallback<string>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the
module resId invalid.
|
| 9001001 | If the
resId invalid.
|
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId.
|
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much.
|
**示例
Stage
:**
**示例:**
```
ts
```
ts
try
{
try
{
this
.
context
.
resourceManager
.
getStringValue
(
$r
(
'
app.string.test
'
).
id
,
(
error
,
value
)
=>
{
this
.
context
.
resourceManager
.
getStringSync
(
$r
(
'
app.string.test
'
).
id
);
if
(
error
!=
null
)
{
}
catch
(
error
)
{
console
.
log
(
"
error is
"
+
error
);
console
.
error
(
`getStringSync failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
else
{
}
let
str
=
value
;
}
});
}
catch
(
error
)
{
console
.
error
(
`callback getStringValue failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
```
```
### getStringSync<sup>10+</sup>
### getStringValue<sup>9+</sup>
getStringSync(resId: number, ...args: Array
<string
|
number
>
): string
getStringValue(resId: number): Promise
<
string
>
用户获取指定资源ID对应的字符串,
使用Promise形式返回
字符串。
用户获取指定资源ID对应的字符串,
根据args参数进行格式化,使用同步方式返回相应
字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**系统能力**
:SystemCapability.Global.ResourceManager
...
@@ -355,42 +352,39 @@ getStringValue(resId: number): Promise<string>
...
@@ -355,42 +352,39 @@ getStringValue(resId: number): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
**返回值:**
| 类型
| 说明 |
| 类型 | 说明 |
| ------
--------------- |
----------- |
| ------
| -----------------
----------- |
|
Promise
<
string
>
| 资源ID值对应的字符串
|
|
string | 资源ID值对应的格式化字符串
|
**错误码:**
**错误码:**
以下错误码的详细介绍请参见
[
资源管理错误码
](
../errorcodes/errorcode-resource-manager.md
)
。
以下错误码的详细介绍请参见
[
资源管理错误码
](
../errorcodes/errorcode-resource-manager.md
)
。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ----------------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
**示例:**
```
ts
```
ts
try
{
try
{
this
.
context
.
resourceManager
.
getStringValue
(
$r
(
'
app.string.test
'
).
id
).
then
(
value
=>
{
this
.
context
.
resourceManager
.
getStringSync
(
$r
(
'
app.string.test
'
).
id
,
"
format string
"
,
10
,
98.78
);
let
str
=
value
;
}).
catch
(
error
=>
{
console
.
log
(
"
getStringValue promise error is
"
+
error
);
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`
promise getStringValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
}
```
```
### getStringSync<sup>9+</sup>
### getStringValue<sup>9+</sup>
getStringSync(resource: Resource): string
getStringValue(resource: Resource, callback: AsyncCallback
<
string
>
): void
用户获取指定resource对象对应的字符串,使用
callback形
式返回字符串。
用户获取指定resource对象对应的字符串,使用
同步方
式返回字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**系统能力**
:SystemCapability.Global.ResourceManager
...
@@ -398,10 +392,15 @@ getStringValue(resource: Resource, callback: AsyncCallback<string>): void
...
@@ -398,10 +392,15 @@ getStringValue(resource: Resource, callback: AsyncCallback<string>): void
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| -------- | ---------------------- | ---- | ---- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的字符串 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------- |
| string | resource对象对应的字符串 |
**错误码:**
**错误码:**
...
@@ -416,46 +415,39 @@ getStringValue(resource: Resource, callback: AsyncCallback<string>): void
...
@@ -416,46 +415,39 @@ getStringValue(resource: Resource, callback: AsyncCallback<string>): void
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.string.test
'
).
id
id
:
$r
(
'
app.string.test
'
).
id
};
};
try
{
try
{
this
.
context
.
resourceManager
.
getStringValue
(
resource
,
(
error
,
value
)
=>
{
this
.
context
.
resourceManager
.
getStringSync
(
resource
);
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
str
=
value
;
}
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`
callback getStringValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
}
```
```
### getStringSync<sup>10+</sup>
### getStringValue<sup>9+</sup>
getStringSync(resource: Resource, ...args: Array
<string
|
number
>
): string
getStringValue(resource: Resource): Promise
<
string
>
用户获取指定resource对象对应的字符串,
使用Promise形式返回
字符串。
用户获取指定resource对象对应的字符串,
根据args参数进行格式化,使用同步方式返回相应
字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**系统能力**
:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| -------- | ---------------------- | ---- | ---- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
--------------- |
---------------- |
| ------
| ------------
---------------- |
|
Promise
<
string
>
| resource对象对应的字符串
|
|
string | resource对象对应的格式化字符串
|
**错误码:**
**错误码:**
...
@@ -466,40 +458,41 @@ getStringValue(resource: Resource): Promise<string>
...
@@ -466,40 +458,41 @@ getStringValue(resource: Resource): Promise<string>
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.string.test
'
).
id
id
:
$r
(
'
app.string.test
'
).
id
};
};
try
{
try
{
this
.
context
.
resourceManager
.
getStringValue
(
resource
).
then
(
value
=>
{
this
.
context
.
resourceManager
.
getStringSync
(
resource
,
"
format string
"
,
10
,
98.78
);
let
str
=
value
;
}).
catch
(
error
=>
{
console
.
log
(
"
getStringValue promise error is
"
+
error
);
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`
promise getStringValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
}
```
```
### getString
ArrayValue
<sup>9+</sup>
### getString
ByNameSync
<sup>9+</sup>
getString
ArrayValue(resId: number, callback: AsyncCallback
<
Array
<
string
>>
): void
getString
ByNameSync(resName: string): string
用户获取指定资源
ID对应的字符串数组,使用callback形式返回字符串数组
。
用户获取指定资源
名称对应的字符串,使用同步方式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------------- |
| ------- | ------ | ---- | ---- |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 异步回调,用于返回获取的字符串数组 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------- |
| string | 资源名称对应的字符串 |
**错误码:**
**错误码:**
...
@@ -507,45 +500,39 @@ getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>
...
@@ -507,45 +500,39 @@ getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
1 | If the resId invalid.
|
| 900100
3 | If the resName invalid.
|
| 900100
2 | If the resource not found by resId.
|
| 900100
4 | If the resource not found by resName.
|
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringArrayValue
(
$r
(
'
app.strarray.test
'
).
id
,
(
error
,
value
)
=>
{
this.context.resourceManager.getStringByNameSync("test");
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
strArray
=
value
;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getStringArrayValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getStringByNameSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getStringByNameSync<sup>10+</sup>
### getStringArrayValue<sup>9+</sup>
getStringByNameSync(resName: string, ...args: Array<string | number>): string
getStringArrayValue(resId: number): Promise
<
Array
<
string
>>
用户获取指定资源
ID对应的字符串数组,使用Promise形式返回字符串数组
。
用户获取指定资源
名称对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ------- | ------ | ---- | ---- |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
| args | Array<string \| number> | 否 | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
---------------------------- |
------------- |
| ------
| ---------------
------------- |
|
Promise
<
Array
<
string
>>
| 资源ID值对应的字符串数组
|
|
string | 资源名称对应的格式化字符串
|
**错误码:**
**错误码:**
...
@@ -553,39 +540,34 @@ getStringArrayValue(resId: number): Promise<Array<string>>
...
@@ -553,39 +540,34 @@ getStringArrayValue(resId: number): Promise<Array<string>>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
1 | If the resId invalid.
|
| 900100
3 | If the resName invalid.
|
| 900100
2 | If the resource not found by resId.
|
| 900100
4 | If the resource not found by resName.
|
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much. |
| 9001008 | If the resource obtained by resName formatting error. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringArrayValue
(
$r
(
'
app.strarray.test
'
).
id
).
then
(
value
=>
{
this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
let
strArray
=
value
;
}).
catch
(
error
=>
{
console
.
log
(
"
getStringArrayValue promise error is
"
+
error
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getStringArrayValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getStringByNameSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getString
Array
Value<sup>9+</sup>
### getStringValue<sup>9+</sup>
getString
ArrayValue(resource: Resource, callback: AsyncCallback
<
Array
<
string
>
>
): void
getString
Value(resId: number, callback: AsyncCallback<string
>): void
用户获取指定
resource对象对应的字符串数组,使用callback形式返回回字符串数组
。
用户获取指定
资源ID对应的字符串,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型
| 必填 | 说明
|
| 参数名 | 类型
| 必填 | 说明
|
| -------- | ---------------------------
------------- | ---- | --
--------------- |
| -------- | ---------------------------
| ---- |
--------------- |
| res
ource |
[
Resource
](
#resource9
)
| 是 | 资源信息
|
| res
Id | number | 是 | 资源ID值
|
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 异步回调,用于返回获取的字符串数组
|
| callback | AsyncCallback<
string> | 是 | 异步回调,用于返回获取的字符串
|
**错误码:**
**错误码:**
...
@@ -593,51 +575,44 @@ getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<stri
...
@@ -593,51 +575,44 @@ getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<stri
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the
resId invalid.
|
| 9001001 | If the
module resId invalid.
|
| 9001002 | If the resource not found by resId.
|
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much.
|
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例
Stage
:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.strarray.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
getString
ArrayValue
(
resource
,
(
error
,
value
)
=>
{
this.context.resourceManager.getString
Value($r('app.string.test').id
, (error, value) => {
if (error != null) {
if (error != null) {
console
.
log
(
"
error is
"
+
error
);
console.log("error is " + error);
} else {
} else {
let
strArray
=
value
;
let str
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getString
Array
Value failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getString
Array
Value<sup>9+</sup>
### getStringValue<sup>9+</sup>
getString
ArrayValue(resource: Resource): Promise
<
Array
<
string
>
>
getString
Value(resId: number): Promise<string
>
用户获取指定
resource对象对应的字符串数组,使用Promise形式返回字符串数组
。
用户获取指定
资源ID对应的字符串,使用Promise形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| -----
--- | ---------------------- | ---- |
---- |
| -----
| ------ | ---- | -
---- |
| res
ource |
[
Resource
](
#resource9
)
| 是 | 资源信息
|
| res
Id | number | 是 | 资源ID值
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
------------- | -------
----------- |
| ---------------------
|
----------- |
| Promise
<
Array
<
string
>>
| resource对象对应的字符串数组
|
| Promise<
string> | 资源ID值对应的字符串
|
**错误码:**
**错误码:**
...
@@ -651,36 +626,33 @@ getStringArrayValue(resource: Resource): Promise<Array<string>>
...
@@ -651,36 +626,33 @@ getStringArrayValue(resource: Resource): Promise<Array<string>>
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.strarray.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
getString
ArrayValue
(
resource
).
then
(
value
=>
{
this.context.resourceManager.getString
Value($r('app.string.test').id
).then(value => {
let
str
Array
=
value
;
let str = value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
getStringArray
promise error is
"
+
error
);
console.log("getStringValue
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise getString
Array
Value failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent
<sup>9+</sup>
### get
StringValue
<sup>9+</sup>
get
MediaContent(resId: number, callback: AsyncCallback
<
Uint8Array
>
): void
get
StringValue(resource: Resource, callback: AsyncCallback<string
>): void
用户获取指定
资源ID对应的媒体文件内容,使用callback形式返回字节数组
。
用户获取指定
resource对象对应的字符串,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型
| 必填 | 说明
|
| 参数名 | 类型
| 必填 | 说明
|
| -------- | ---------------------------
---- | ---- | ---
--------------- |
| -------- | ---------------------------
| ---- |
--------------- |
| res
Id | number | 是 | 资源ID值
|
| res
ource | [Resource](#resource9) | 是 | 资源信息
|
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容
|
| callback | AsyncCallback<
string> | 是 | 异步回调,用于返回获取的字符串
|
**错误码:**
**错误码:**
...
@@ -690,37 +662,49 @@ getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void
...
@@ -690,37 +662,49 @@ getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.string.test').id
};
try {
try {
this
.
context
.
resourceManager
.
get
MediaContent
(
$r
(
'
app.media.test
'
).
id
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
StringValue(resource
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
log
(
"
error is
"
+
error
);
console.log("error is " + error);
}
else
{
} else {
let
media
=
value
;
let str
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
MediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
StringValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent<sup>10
+</sup>
### get
StringValue<sup>9
+</sup>
get
MediaContent(resId: number, density: number, callback: AsyncCallback
<
Uint8Array
>
): void
get
StringValue(resource: Resource): Promise<string>
用户获取指定
资源ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组
。
用户获取指定
resource对象对应的字符串,使用Promise形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**
参数:**
**
模型约束**:此接口仅可在Stage模型下使用。
| 参数名 | 类型 | 必填 | 说明 |
**参数:**
| -------- | ------------------------------- | ---- | ------------------ |
| resId | number | 是 | 资源ID值 |
| 参数名 | 类型 | 必填 | 说明 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| -------- | ---------------------- | ---- | ---- |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise<string> | resource对象对应的字符串 |
**错误码:**
**错误码:**
...
@@ -730,41 +714,85 @@ getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8
...
@@ -730,41 +714,85 @@ getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.string.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContent
(
$r
(
'
app.media.test
'
).
id
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.getStringValue(resource).then(value => {
if
(
error
!=
null
)
{
let str = value;
console
.
error
(
`callback getMediaContent failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}).catch(error => {
}
else
{
console.log("getStringValue promise error is " + error);
let
media
=
value
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getMediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getStringValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent
<sup>9+</sup>
### get
StringByName
<sup>9+</sup>
get
MediaContent(resId: number): Promise
<
Uint8Array
>
get
StringByName(resName: string, callback: AsyncCallback<string>): void
用户获取指定资源
ID对应的媒体文件内容,使用Promise形式返回字节数组
。
用户获取指定资源
名称对应的字符串,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| -------- | --------------------------- | ---- | --------------- |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的字符串 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getStringByName("test", (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let str = value;
}
});
} catch (error) {
console.error(
`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getStringByName<sup>9+</sup>
getStringByName(resName: string): Promise<string>
用户获取指定资源名称对应的字符串,使用Promise形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
---- | ----
---------- |
| ---------------------
|
---------- |
| Promise
<
Uint8Array
>
| 资源ID值对应的媒体文件内容
|
| Promise<
string> | 资源名称对应的字符串
|
**错误码:**
**错误码:**
...
@@ -772,27 +800,28 @@ getMediaContent(resId: number): Promise<Uint8Array>
...
@@ -772,27 +800,28 @@ getMediaContent(resId: number): Promise<Uint8Array>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMediaContent
(
$r
(
'
app.media.test
'
).
id
).
then
(
value
=>
{
this.context.resourceManager.getStringByName("test"
).then(value => {
let
media
=
value
;
let str
= value;
}).
catch
(
error
=>
{
}).catch(error => {
console
.
log
(
"
getMediaContent
promise error is
"
+
error
);
console.log("getStringByName
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
MediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
StringByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent
<sup>10+</sup>
### get
StringArrayValueSync
<sup>10+</sup>
get
MediaContent(resId: number, density: number): Promise
<
Uint8Array
>
get
StringArrayValueSync(resId: number): Array<string
>
用户获取指定资源ID对应的
指定屏幕密度媒体文件内容,使用Promise形式返回字节
数组。
用户获取指定资源ID对应的
字符串数组,使用同步方式返回字符串
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -801,13 +830,12 @@ getMediaContent(resId: number, density: number): Promise<Uint8Array>
...
@@ -801,13 +830,12 @@ getMediaContent(resId: number, density: number): Promise<Uint8Array>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
---- | ---
----------- |
| ---------------------
|
----------- |
|
Promise
<
Uint8Array
>
| 资源ID值对应的媒体文件内容
|
|
Array<string> | 资源ID值对应的字符串数组
|
**错误码:**
**错误码:**
...
@@ -817,25 +845,22 @@ getMediaContent(resId: number, density: number): Promise<Uint8Array>
...
@@ -817,25 +845,22 @@ getMediaContent(resId: number, density: number): Promise<Uint8Array>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMediaContent
(
$r
(
'
app.media.test
'
).
id
,
120
).
then
(
value
=>
{
this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id);
let
media
=
value
;
}).
catch
(
error
=>
{
console
.
error
(
`promise getMediaContent failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getStringArrayValueSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent<sup>9
+</sup>
### get
StringArrayValueSync<sup>10
+</sup>
get
MediaContent(resource: Resource, callback: AsyncCallback
<
Uint8Array
>
): void
get
StringArrayValueSync(resource: Resource): Array<string>
用户获取指定resource对象对应的
媒体文件内容,使用callback形式返回字节
数组。
用户获取指定resource对象对应的
字符串数组,使用同步方式返回字符串
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -843,10 +868,15 @@ getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>):
...
@@ -843,10 +868,15 @@ getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>):
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------ |
| ----- | ------ | ---- | ----- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ----------- |
| Array<string> | resource对象对应的字符串数组 |
**错误码:**
**错误码:**
...
@@ -856,44 +886,36 @@ getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>):
...
@@ -856,44 +886,36 @@ getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>):
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName
:
"
com.example.myapplication
"
,
bundleName: "com.example.myapplication",
moduleName
:
"
entry
"
,
moduleName: "entry",
id
:
$r
(
'
app.media
.test
'
).
id
id: $r('app.strarray
.test').id
};
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContent
(
resource
,
(
error
,
value
)
=>
{
this.context.resourceManager.getStringArrayValueSync(resource);
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
media
=
value
;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getMediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getStringArrayValueSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent<sup>10
+</sup>
### get
StringArrayValue<sup>9
+</sup>
get
MediaContent(resource: Resource, density: number, callback: AsyncCallback
<
Uint8Array
>
): void
get
StringArrayValue(resId: number, callback: AsyncCallback<Array<string>
>): void
用户获取指定
resource对象对应的指定屏幕密度媒体文件内容,使用callback形式返回字节
数组。
用户获取指定
资源ID对应的字符串数组,使用callback形式返回字符串
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------ |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resId | number | 是 | 资源ID值 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回获取的字符串数组 |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -903,48 +925,42 @@ getMediaContent(resource: Resource, density: number, callback: AsyncCallback<
...
@@ -903,48 +925,42 @@ getMediaContent(resource: Resource, density: number, callback: AsyncCallback<
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.media.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
get
MediaContent
(
resource
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
StringArrayValue($r('app.strarray.test').id
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
error
(
`callback getMediaContent failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("error is " + error
);
}
else
{
} else {
let
media
=
value
;
let strArray
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
MediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
StringArrayValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent
<sup>9+</sup>
### get
StringArrayValue
<sup>9+</sup>
get
MediaContent(resource: Resource): Promise
<
Uint8Array
>
get
StringArrayValue(resId: number): Promise<Array<string>
>
用户获取指定
resource对象对应的媒体文件内容,使用Promise形式返回字节
数组。
用户获取指定
资源ID对应的字符串数组,使用Promise形式返回字符串
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| -----
--- | ---------------------- | ---- |
---- |
| -----
| ------ | ---- | -
---- |
| res
ource |
[
Resource
](
#resource9
)
| 是 | 资源信息
|
| res
Id | number | 是 | 资源ID值
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| -------------------------
| ------
------------- |
| -------------------------
--------- |
------------- |
| Promise
<
Uint8Array
>
| resource对象对应的媒体文件内容
|
| Promise<
Array<string>> | 资源ID值对应的字符串数组
|
**错误码:**
**错误码:**
...
@@ -954,30 +970,26 @@ getMediaContent(resource: Resource): Promise<Uint8Array>
...
@@ -954,30 +970,26 @@ getMediaContent(resource: Resource): Promise<Uint8Array>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.media.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
get
MediaContent
(
resource
).
then
(
value
=>
{
this.context.resourceManager.get
StringArrayValue($r('app.strarray.test').id
).then(value => {
let
media
=
value
;
let
strArray
= value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
get
MediaContent
promise error is
"
+
error
);
console.log("get
StringArrayValue
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
MediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
StringArrayValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContent<sup>10
+</sup>
### get
StringArrayValue<sup>9
+</sup>
get
MediaContent(resource: Resource, density: number): Promise
<
Uint8Array
>
get
StringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void
用户获取指定resource对象对应的
指定屏幕密度媒体文件内容,使用Promise形式返回字节
数组。
用户获取指定resource对象对应的
字符串数组,使用callback形式返回回字符串
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -985,16 +997,10 @@ getMediaContent(resource: Resource, density: number): Promise<Uint8Array>
...
@@ -985,16 +997,10 @@ getMediaContent(resource: Resource, density: number): Promise<Uint8Array>
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回获取的字符串数组 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------- |
| Promise
<
Uint8Array
>
| resource对象对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1004,39 +1010,49 @@ getMediaContent(resource: Resource, density: number): Promise<Uint8Array>
...
@@ -1004,39 +1010,49 @@ getMediaContent(resource: Resource, density: number): Promise<Uint8Array>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName
:
"
com.example.myapplication
"
,
bundleName: "com.example.myapplication",
moduleName
:
"
entry
"
,
moduleName: "entry",
id
:
$r
(
'
app.media
.test
'
).
id
id: $r('app.strarray
.test').id
};
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContent
(
resource
,
120
).
then
(
value
=>
{
this.context.resourceManager.getStringArrayValue(resource, (error, value) => {
let
media
=
value
;
if (error != null) {
}).
catch
(
error
=>
{
console.log("error is " + error);
console
.
error
(
`promise getMediaContent failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
} else {
let strArray = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaContent
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getStringArrayValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64
<sup>9+</sup>
### get
StringArrayValue
<sup>9+</sup>
get
MediaContentBase64(resId: number, callback: AsyncCallback
<
string
>
): void
get
StringArrayValue(resource: Resource): Promise<Array<string>>
用户获取指定
资源ID对应的图片资源Base64编码,使用callback形式返回字符串
。
用户获取指定
resource对象对应的字符串数组,使用Promise形式返回字符串数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ |
| -------- | ---------------------- | ---- | ---- |
| resId | number | 是 | 资源ID值 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的图片资源Base64编码 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ------------------ |
| Promise<Array<string>> | resource对象对应的字符串数组 |
**错误码:**
**错误码:**
...
@@ -1046,37 +1062,40 @@ getMediaContentBase64(resId: number, callback: AsyncCallback<string>): voi
...
@@ -1046,37 +1062,40 @@ getMediaContentBase64(resId: number, callback: AsyncCallback<string>): voi
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.strarray.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContentBase64
(
$r
(
'
app.media.test
'
).
id
,
(
error
,
value
)
=>
{
this.context.resourceManager.getStringArrayValue(resource).then(value => {
if
(
error
!=
null
)
{
let strArray = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
else
{
console.log("getStringArray promise error is " + error);
let
media
=
value
;
});
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getMediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getStringArrayValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64<sup>10
+</sup>
### get
StringArrayByName<sup>9
+</sup>
get
MediaContentBase64(resId: number, density: number, callback: AsyncCallback
<
string
>
): void
get
StringArrayByName(resName: string, callback: AsyncCallback<Array<string>
>): void
用户获取指定资源
ID对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串
。
用户获取指定资源
名称对应的字符串数组,使用callback形式返回字符串数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Array<string>> | 是 | 异步回调,用于返回获取的字符串数组 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -1084,43 +1103,44 @@ getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<
...
@@ -1084,43 +1103,44 @@ getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
MediaContentBase64
(
$r
(
'
app.media.test
'
).
id
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
StringArrayByName("test"
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
error
(
`callback getMediaContentBase64 failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("error is " + error
);
}
else
{
} else {
let
media
=
value
;
let strArray
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
MediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
StringArrayByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64
<sup>9+</sup>
### get
StringArrayByName
<sup>9+</sup>
get
MediaContentBase64(resId: number): Promise
<
string
>
get
StringArrayByName(resName: string): Promise<Array<string>
>
用户获取指定资源
ID对应的图片资源Base64编码,使用Promise形式返回字符串
。
用户获取指定资源
名称对应的字符串数组,使用Promise形式返回字符串数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| -----
| ------ | ---- | -
---- |
| -----
-- | ------ | ---- |
---- |
| res
Id | number | 是 | 资源ID值
|
| res
Name | string | 是 | 资源名称
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
| --------
------------ |
| ---------------------
------------- |
------------ |
| Promise
<
string
>
| 资源ID值对应的图片资源Base64编码
|
| Promise<
Array<string>> | 资源名称对应的字符串数组
|
**错误码:**
**错误码:**
...
@@ -1128,27 +1148,28 @@ getMediaContentBase64(resId: number): Promise<string>
...
@@ -1128,27 +1148,28 @@ getMediaContentBase64(resId: number): Promise<string>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
MediaContentBase64
(
$r
(
'
app.media.test
'
).
id
).
then
(
value
=>
{
this.context.resourceManager.get
StringArrayByName("test"
).then(value => {
let
media
=
value
;
let strArray
= value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
getMediaContentBase64
promise error is
"
+
error
);
console.log("getStringArrayByName
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
MediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
StringArrayByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64
<sup>10+</sup>
### get
PluralStringValueSync
<sup>10+</sup>
get
MediaContentBase64(resId: number, density: number): Promise
<
string
>
get
PluralStringValueSync(resId: number, num: number): string
用户获取指定资源ID对应的指定屏幕密度图片资源Base64编码,使用Promise形
式返回字符串。
根据指定数量获取指定ID字符串表示的单复数字符串,使用同步方
式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -1157,13 +1178,13 @@ getMediaContentBase64(resId: number, density: number): Promise<string>
...
@@ -1157,13 +1178,13 @@ getMediaContentBase64(resId: number, density: number): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度
|
|
num | number | 是 | 数量值
|
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| --------
------------- | ---------
----------- |
| --------
|
----------- |
|
Promise
<
string
>
| 资源ID值对应的图片资源Base64编码
|
|
string | 根据指定数量获取指定ID字符串表示的单复数字符串
|
**错误码:**
**错误码:**
...
@@ -1173,36 +1194,39 @@ getMediaContentBase64(resId: number, density: number): Promise<string>
...
@@ -1173,36 +1194,39 @@ getMediaContentBase64(resId: number, density: number): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMediaContentBase64
(
$r
(
'
app.media.test
'
).
id
,
120
).
then
(
value
=>
{
this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1);
let
media
=
value
;
}).
catch
(
error
=>
{
console
.
error
(
`promise getMediaContentBase64 failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getPluralStringValueSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64<sup>9
+</sup>
### get
PluralStringValueSync<sup>10
+</sup>
get
MediaContentBase64(resource: Resource, callback: AsyncCallback
<
string
>
): void
get
PluralStringValueSync(resource: Resource, num: number): string
用户获取指定resource对象对应的图片资源Base64编码,使用callback形
式返回字符串。
根据指定数量获取指定resource对象表示的单复数字符串,使用同步方
式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ |
| ----- | ------ | ---- | ----- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| num | number | 是 | 数量值 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ----------- |
| string | 根据指定数量获取指定resource对象表示的单复数字符串 |
**错误码:**
**错误码:**
...
@@ -1212,44 +1236,37 @@ getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>)
...
@@ -1212,44 +1236,37 @@ getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>)
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName
:
"
com.example.myapplication
"
,
bundleName: "com.example.myapplication",
moduleName
:
"
entry
"
,
moduleName: "entry",
id
:
$r
(
'
app.media
.test
'
).
id
id: $r('app.plural
.test').id
};
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContentBase64
(
resource
,
(
error
,
value
)
=>
{
this.context.resourceManager.getPluralStringValueSync(resource, 1);
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
media
=
value
;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getMediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
getPluralStringValueSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64<sup>10
+</sup>
### get
PluralStringValue<sup>9
+</sup>
get
MediaContentBase64(resource: Resource, density
: number, callback: AsyncCallback
<
string
>
): void
get
PluralStringValue(resId: number, num
: number, callback: AsyncCallback<string>): void
用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码
,使用callback形式返回字符串。
根据指定数量获取指定ID字符串表示的单复数字符串
,使用callback形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| -------- | --------------------------- | ---- | ------------------------ |
| -------- | --------------------------- | ---- | ------------------------
-------
|
| res
ource |
[
Resource
](
#resource9
)
| 是 | 资源信息
|
| res
Id | number | 是 | 资源ID值
|
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度
|
|
num | number | 是 | 数量值
|
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,
用于返回获取的图片资源Base64编码
|
| callback | AsyncCallback<string> | 是 | 异步回调,
返回根据指定数量获取指定ID字符串表示的单复数字符串
|
**错误码:**
**错误码:**
...
@@ -1259,48 +1276,43 @@ getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallba
...
@@ -1259,48 +1276,43 @@ getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallba
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.media.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
get
MediaContentBase64
(
resource
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
PluralStringValue($r("app.plural.test").id, 1
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
error
(
`callback getMediaContentBase64 failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("error is " + error
);
}
else
{
} else {
let
media
=
value
;
let str
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
MediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
PluralStringValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64
<sup>9+</sup>
### get
PluralStringValue
<sup>9+</sup>
get
MediaContentBase64(resource: Resource
): Promise
<
string
>
get
PluralStringValue(resId: number, num: number
): Promise<string>
用户获取指定resource对象对应的图片资源Base64编码
,使用Promise形式返回字符串。
根据指定数量获取对指定ID字符串表示的单复数字符串
,使用Promise形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| ----- | ------ | ---- | ----- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resId | number | 是 | 资源ID值 |
| num | number | 是 | 数量值 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| --------------------- | ------------------------- |
| --------------------- | ------------------------- |
| Promise
<
string
>
|
resource对象对应的图片资源Base64编码
|
| Promise<string> |
根据提供的数量获取对应ID字符串表示的单复数字符串
|
**错误码:**
**错误码:**
...
@@ -1310,30 +1322,26 @@ getMediaContentBase64(resource: Resource): Promise<string>
...
@@ -1310,30 +1322,26 @@ getMediaContentBase64(resource: Resource): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.media.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
get
MediaContentBase64
(
resource
).
then
(
value
=>
{
this.context.resourceManager.get
PluralStringValue($r("app.plural.test").id, 1
).then(value => {
let
media
=
value
;
let str
= value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
getMediaContentBase64
promise error is
"
+
error
);
console.log("getPluralStringValue
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
MediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
PluralStringValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
MediaContentBase64<sup>10
+</sup>
### get
PluralStringValue<sup>9
+</sup>
get
MediaContentBase64(resource: Resource, density: number): Promise
<
string
>
get
PluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void
用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用Promise
形式返回字符串。
根据指定数量获取指定resource对象表示的单复数字符串,使用callback
形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -1341,16 +1349,11 @@ getMediaContentBase64(resource: Resource, density: number): Promise<string>
...
@@ -1341,16 +1349,11 @@ getMediaContentBase64(resource: Resource, density: number): Promise<string>
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| -------- | --------------------------- | ---- | ------------------------------------ |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| num | number | 是 | 数量值 |
| callback | AsyncCallback<string> | 是 | 异步回调,返回根据指定数量获取指定resource对象表示的单复数字符串 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise
<
string
>
| resource对象对应的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -1360,159 +1363,140 @@ getMediaContentBase64(resource: Resource, density: number): Promise<string>
...
@@ -1360,159 +1363,140 @@ getMediaContentBase64(resource: Resource, density: number): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName
:
"
com.example.myapplication
"
,
bundleName: "com.example.myapplication",
moduleName
:
"
entry
"
,
moduleName: "entry",
id
:
$r
(
'
app.media
.test
'
).
id
id: $r('app.plural
.test').id
};
};
try {
try {
this
.
context
.
resourceManager
.
getMediaContentBase64
(
resource
,
120
).
then
(
value
=>
{
this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => {
let
media
=
value
;
if (error != null) {
}).
catch
(
error
=>
{
console.log("error is " + error);
console
.
error
(
`promise getMediaContentBase64 failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
} else {
let str = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaContentBase64
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getPluralStringValue
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
Configuration
### get
PluralStringValue<sup>9+</sup>
get
Configuration(callback: AsyncCallback
<
Configuration
>
): void
get
PluralStringValue(resource: Resource, num: number): Promise<string>
用户获取设备的Configuration,使用callback形式返回Configuration对象
。
根据指定数量获取对指定resource对象表示的单复数字符串,使用Promise形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------- |
| -------- | ---------------------- | ---- | ---- |
| callback | AsyncCallback
<
[Configuration](#configuration)
>
| 是 | 异步回调,用于返回设备的Configuration |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| num | number | 是 | 数量值 |
**示例:**
**返回值:**
```
ts
try
{
this
.
context
.
resourceManager
.
getConfiguration
((
error
,
value
)
=>
{
if
(
error
!=
null
)
{
console
.
error
(
"
getConfiguration callback error is
"
+
error
);
}
else
{
let
direction
=
value
.
direction
;
let
locale
=
value
.
locale
;
}
});
}
catch
(
error
)
{
console
.
error
(
"
getConfiguration callback error is
"
+
error
);
}
```
### getConfiguration
getConfiguration(): Promise
<
Configuration
>
用户获取设备的Configuration,使用Promise形式返回Configuration对象。
| 类型 | 说明 |
| --------------------- | ------------------------------ |
| Promise<string> | 根据提供的数量获取对应resource对象表示的单复数字符串 |
**
系统能力**
:SystemCapability.Global.ResourceManager
**
错误码:**
**返回值:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 类型 | 说明 |
| 错误码ID | 错误信息 |
| ---------------------------------------- | ---------------- |
| -------- | ---------------------------------------- |
| Promise
<
[Configuration](#configuration)
>
| 设备的Configuration |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.plural.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getConfiguration
().
then
(
value
=>
{
this.context.resourceManager.getPluralStringValue(resource, 1).then(value => {
let
direction
=
value
.
direction
;
let str = value;
let
locale
=
value
.
locale
;
}).catch(error => {
}).catch(error => {
console
.
error
(
"
getConfiguration
promise error is
"
+
error
);
console.
log("getPluralStringValue
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
"
getConfiguration promise error is
"
+
error
);
console.error(
`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getPluralStringByName<sup>9+</sup>
### getDeviceCapability
getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void
getDeviceCapability(callback: AsyncCallback
<
DeviceCapability
>
): void
用户获取设备的DeviceCapability,使用callback形式返回DeviceCapability对象
。
根据传入的数量值,获取资源名称对应的字符串资源,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
| -------- | --------------------------- | ---- | ----------------------------- |
| callback | AsyncCallback
<
[DeviceCapability](#devicecapability)
>
| 是 | 异步回调,用于返回设备的DeviceCapability |
| resName | string | 是 | 资源名称 |
| num | number | 是 | 数量值 |
| callback | AsyncCallback<string> | 是 | 异步回调,返回根据传入的数量值获取资源名称对应的字符串资源 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
DeviceCapability
(
(
error
,
value
)
=>
{
this.context.resourceManager.get
PluralStringByName("test", 1,
(error, value) => {
if (error != null) {
if (error != null) {
console
.
error
(
"
getDeviceCapability callback
error is
"
+
error
);
console.
log("
error is " + error);
} else {
} else {
let
screenDensity
=
value
.
screenDensity
;
let str = value;
let
deviceType
=
value
.
deviceType
;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
"
getDeviceCapability callback error is
"
+
error
);
console.error(
`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getPluralStringByName<sup>9+</sup>
### getDeviceCapability
getPluralStringByName(resName: string, num: number): Promise<string>
getDeviceCapability(): Promise
<
DeviceCapability
>
用户获取设备的DeviceCapability,使用Promise形式返回DeviceCapability对象
。
根据传入的数量值,获取资源名称对应的字符串资源,使用Promise形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**返回值:**
**参数:**
| 类型 | 说明 |
| ---------------------------------------- | ------------------- |
| Promise
<
[DeviceCapability](#devicecapability)
>
| 设备的DeviceCapability |
**示例:**
```
ts
try
{
this
.
context
.
resourceManager
.
getDeviceCapability
().
then
(
value
=>
{
let
screenDensity
=
value
.
screenDensity
;
let
deviceType
=
value
.
deviceType
;
}).
catch
(
error
=>
{
console
.
error
(
"
getDeviceCapability promise error is
"
+
error
);
});
}
catch
(
error
)
{
console
.
error
(
"
getDeviceCapability promise error is
"
+
error
);
}
```
### getPluralStringValue<sup>9+</sup>
getPluralStringValue(resId: number, num: number, callback: AsyncCallback
<
string
>
): void
根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| num | number | 是 | 数量值 |
**
参数:**
**
返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| 类型 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------- |
| --------------------- | ---------------------- |
| resId | number | 是 | 资源ID值 |
| Promise<string> | 根据传入的数量值获取资源名称对应的字符串资源 |
| num | number | 是 | 数量值 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 |
**错误码:**
**错误码:**
...
@@ -1520,46 +1504,43 @@ getPluralStringValue(resId: number, num: number, callback: AsyncCallback<stri
...
@@ -1520,46 +1504,43 @@ getPluralStringValue(resId: number, num: number, callback: AsyncCallback<stri
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
1 | If the resId invalid.
|
| 900100
3 | If the resName invalid.
|
| 900100
2 | If the resource not found by resId.
|
| 900100
4 | If the resource not found by resName.
|
| 9001006 | If the resource re-ref too much. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getPluralStringValue
(
$r
(
"
app.plural.test
"
).
id
,
1
,
(
error
,
value
)
=>
{
this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
if
(
error
!=
null
)
{
let str = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
else
{
console.log("getPluralStringByName promise error is " + error);
let
str
=
value
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getPluralStringValu
e failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getPluralStringByNam
e failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMediaContentSync<sup>10+</sup>
### getPluralStringValue<sup>9+</sup>
getMediaContentSync(resId: number, density?: number): Uint8Array
getPluralStringValue(resId: number, num: number): Promise
<
string
>
根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串
。
用户获取指定资源ID对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
|
num | number | 是 | 数量值
|
|
[density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度
|
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| --------
------------- | --------------
----------- |
| --------
|
----------- |
|
Promise
<
string
>
| 根据提供的数量获取对应ID字符串表示的单复数字符串
|
|
Uint8Array | 资源ID对应的媒体文件内容
|
**错误码:**
**错误码:**
...
@@ -1569,38 +1550,44 @@ getPluralStringValue(resId: number, num: number): Promise<string>
...
@@ -1569,38 +1550,44 @@ getPluralStringValue(resId: number, num: number): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getPluralStringValue
(
$r
(
"
app.plural.test
"
).
id
,
1
).
then
(
value
=>
{
this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // 默认屏幕密度
let
str
=
value
;
}).
catch
(
error
=>
{
console
.
log
(
"
getPluralStringValue promise error is
"
+
error
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise getPluralStringValue failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // 指定屏幕密度
} catch (error) {
console.error(
`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
PluralStringValue<sup>9
+</sup>
### get
MediaContentSync<sup>10
+</sup>
get
PluralStringValue(resource: Resource, num: number, callback: AsyncCallback
<
string
>
): void
get
MediaContentSync(resource: Resource, density?: number): Uint8Array
根据指定数量获取指定resource对象表示的单复数字符串,使用callback形式返回字符串
。
用户获取指定resource对象对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------ |
| ----- | ------ | ---- | ----- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| num | number | 是 | 数量值 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,返回根据指定数量获取指定resource对象表示的单复数字符串 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ----------- |
| Uint8Array | resource对象对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1610,50 +1597,41 @@ getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<
...
@@ -1610,50 +1597,41 @@ getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName
:
"
com.example.myapplication
"
,
bundleName: "com.example.myapplication",
moduleName
:
"
entry
"
,
moduleName: "entry",
id
:
$r
(
'
app.plural
.test
'
).
id
id: $r('app.media
.test').id
};
};
try {
try {
this
.
context
.
resourceManager
.
getPluralStringValue
(
resource
,
1
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaContentSync(resource); // 默认屏幕密度
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
str
=
value
;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getPluralStringValue failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getMediaContentSync(resource, 120); // 指定屏幕密度
} catch (error) {
console.error(
`getMediaContentSync failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
PluralStringValue
<sup>9+</sup>
### get
MediaContent
<sup>9+</sup>
get
PluralStringValue(resource: Resource, num: number): Promise
<
string
>
get
MediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void
根据指定数量获取对指定resource对象表示的单复数字符串,使用Promise形式返回字符串
。
用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| -------- | ------------------------------- | ---- | ------------------ |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resId | number | 是 | 资源ID值 |
| num | number | 是 | 数量值 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------ |
| Promise
<
string
>
| 根据提供的数量获取对应resource对象表示的单复数字符串 |
**错误码:**
**错误码:**
...
@@ -1663,41 +1641,37 @@ getPluralStringValue(resource: Resource, num: number): Promise<string>
...
@@ -1663,41 +1641,37 @@ getPluralStringValue(resource: Resource, num: number): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.plural.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
getPluralStringValue
(
resource
,
1
).
then
(
value
=>
{
this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
let
str
=
value
;
if (error != null) {
}).
catch
(
error
=>
{
console.log("error is " + error);
console
.
log
(
"
getPluralStringValue promise error is
"
+
error
);
} else {
let media = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getPluralStringValue
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getMediaContent
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMediaContent<sup>10+</sup>
### getRawFileContent<sup>9+</sup>
getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8Array>): void
getRawFileContent(path: string, callback: AsyncCallback
<
Uint8Array
>
): void
用户获取
resources/rawfile目录下对应的rawfile
文件内容,使用callback形式返回字节数组。
用户获取
指定资源ID对应的指定屏幕密度媒体
文件内容,使用callback形式返回字节数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ----------------------- |
| -------- | ------------------------------- | ---- | ------------------ |
| path | string | 是 | rawfile文件路径 |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的rawfile文件内容 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1705,42 +1679,43 @@ getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void
...
@@ -1705,42 +1679,43 @@ getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
RawFileContent
(
"
test.xml
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
MediaContent($r('app.media.test').id, 120
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
log
(
"
error is
"
+
error
);
console.error(
`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`
);
}
else
{
} else {
let
rawFile
=
value
;
let media
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
RawFile
Content failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
Media
Content failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
RawFile
Content<sup>9+</sup>
### get
Media
Content<sup>9+</sup>
get
RawFileContent(path: string
): Promise
<
Uint8Array
>
get
MediaContent(resId: number
): Promise<Uint8Array>
用户获取
resources/rawfile目录下对应的rawfile
文件内容,使用Promise形式返回字节数组。
用户获取
指定资源ID对应的媒体
文件内容,使用Promise形式返回字节数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| ----
| ------ | ---- | ------
----- |
| ----
- | ------ | ---- |
----- |
|
path | string | 是 | rawfile文件路径
|
|
resId | number | 是 | 资源ID值
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ------------------------- | ----------- |
| ------------------------- | -----------
---
|
| Promise
<
Uint8Array
>
|
rawfile
文件内容 |
| Promise<Uint8Array> |
资源ID值对应的媒体
文件内容 |
**错误码:**
**错误码:**
...
@@ -1748,36 +1723,42 @@ getRawFileContent(path: string): Promise<Uint8Array>
...
@@ -1748,36 +1723,42 @@ getRawFileContent(path: string): Promise<Uint8Array>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
RawFileContent
(
"
test.xml
"
).
then
(
value
=>
{
this.context.resourceManager.get
MediaContent($r('app.media.test').id
).then(value => {
let
rawFile
=
value
;
let media
= value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
getRawFile
Content promise error is
"
+
error
);
console.log("getMedia
Content promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
RawFile
Content failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
Media
Content failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMediaContent<sup>10+</sup>
### getRawFd<sup>9+</sup>
getMediaContent(resId: number, density: number): Promise<Uint8Array>
getRawFd(path: string, callback: AsyncCallback
<
RawFileDescriptor
>
): void
用户获取
resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回
。
用户获取
指定资源ID对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| ----- | ------ | ---- | ----- |
| path | string | 是 | rawfile文件路径 |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback
<
[RawFileDescriptor](#rawfiledescriptor8)
>
| 是 | 异步回调,用于返回获取的rawfile文件的descriptor |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | -------------- |
| Promise<Uint8Array> | 资源ID值对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1785,44 +1766,38 @@ getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void
...
@@ -1785,44 +1766,38 @@ getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getRawFd
(
"
test.xml
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then(value => {
if
(
error
!=
null
)
{
let media = value;
console
.
log
(
`callback getRawFd failed error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}).catch(error => {
}
else
{
console.error(
`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`
);
let
fd
=
value
.
fd
;
let
offset
=
value
.
offset
;
let
length
=
value
.
length
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getRawFd
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise getMediaContent
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
RawFd
<sup>9+</sup>
### get
MediaContent
<sup>9+</sup>
get
RawFd(path: string): Promise
<
RawFileDescriptor
>
get
MediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void
用户获取
resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回
。
用户获取
指定resource对象对应的媒体文件内容,使用callback形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**模型约束**:此接口仅可在Stage模型下使用。
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ----------- |
| path | string | 是 | rawfile文件路径 |
**
返回值:**
**
参数:**
| 类型 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ---------------------------------------- | ------------------- |
| -------- | ------------------------------- | ---- | ------------------ |
| Promise
<
[RawFileDescriptor](#rawfiledescriptor8)
>
| rawfile文件descriptor |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1830,37 +1805,46 @@ getRawFd(path: string): Promise<RawFileDescriptor>
...
@@ -1830,37 +1805,46 @@ getRawFd(path: string): Promise<RawFileDescriptor>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
get
RawFd
(
"
test.xml
"
).
then
(
value
=>
{
this.context.resourceManager.get
MediaContent(resource, (error, value)
=> {
let
fd
=
value
.
fd
;
if (error != null) {
let
offset
=
value
.
offset
;
console.log("error is " + error)
;
let
length
=
value
.
length
;
} else {
}).
catch
(
error
=>
{
let media = value;
console
.
log
(
`promise getRawFd error error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getRawFd
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getMediaContent
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
RawFileLis
t<sup>10+</sup>
### get
MediaConten
t<sup>10+</sup>
get
RawFileList(path: string, callback: AsyncCallback
<
Array\
<string
\
>
>
): void;
get
MediaContent(resource: Resource, density: number, callback: AsyncCallback<Uint8Array>): void
用户获取
resources/rawfile目录下文件夹及文件列表,使用callback形式返回文件列表的字符串
数组。
用户获取
指定resource对象对应的指定屏幕密度媒体文件内容,使用callback形式返回字节
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ----------------------- |
| -------- | ------------------------------- | ---- | ------------------ |
| path | string | 是 | rawfile文件夹路径 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
Array\
<string
\
>
>
| 是 | 异步回调,用于返回获取rawfile文件目录下的文件列表 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1868,42 +1852,50 @@ getRawFileList(path: string, callback: AsyncCallback<Array\<string\>>): vo
...
@@ -1868,42 +1852,50 @@ getRawFileList(path: string, callback: AsyncCallback<Array\<string\>>): vo
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
try
{
// 传入""表示获取rawfile根目录下的文件列表
let resource = {
this
.
context
.
resourceManager
.
getRawFileList
(
""
,
(
error
,
value
)
=>
{
bundleName: "com.example.myapplication",
if
(
error
!=
null
)
{
moduleName: "entry",
console
.
error
(
`callback getRawFileList failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
id: $r('app.media.test').id
}
else
{
};
let
rawFile
=
value
;
try {
}
this.context.resourceManager.getMediaContent(resource, 120, (error, value) => {
if (error != null) {
console.error(
`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`
);
} else {
let media = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
RawFileLis
t failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
MediaConten
t failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
RawFileList<sup>10
+</sup>
### get
MediaContent<sup>9
+</sup>
get
RawFileList(path: string): Promise
<
Array\
<string
\
>
>
get
MediaContent(resource: Resource): Promise<Uint8Array
>
用户获取
resources/rawfile目录下文件夹及文件列表,使用Promise形式返回文件列表字符串
数组。
用户获取
指定resource对象对应的媒体文件内容,使用Promise形式返回字节
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| ----
| ------ | ---- | -------
---- |
| ----
---- | ---------------------- | ---- |
---- |
|
path | string | 是 | rawfile文件夹路径
|
|
resource | [Resource](#resource9) | 是 | 资源信息
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ------------------------- | ----------- |
| ------------------------- | -----------
--------
|
| Promise
<
Array\
<string
\
>
>
| rawfile文件目录下的文件列表
|
| Promise<
Uint8Array> | resource对象对应的媒体文件内容
|
**错误码:**
**错误码:**
...
@@ -1911,35 +1903,49 @@ getRawFileList(path: string): Promise<Array\<string\>>
...
@@ -1911,35 +1903,49 @@ getRawFileList(path: string): Promise<Array\<string\>>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
try
{
// 传入""表示获取rawfile根目录下的文件列表
let resource = {
this
.
context
.
resourceManager
.
getRawFileList
(
""
).
then
(
value
=>
{
bundleName: "com.example.myapplication",
let
rawFile
=
value
;
moduleName: "entry",
id: $r('app.media.test').id
};
try {
this.context.resourceManager.getMediaContent(resource).then(value => {
let media = value;
}).catch(error => {
}).catch(error => {
console
.
error
(
`promise getRawFileList failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("getMediaContent promise error is " + error
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
RawFileLis
t failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
MediaConten
t failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
###
closeRawFd<sup>9
+</sup>
###
getMediaContent<sup>10
+</sup>
closeRawFd(path: string, callback: AsyncCallback
<
void
>
): void
getMediaContent(resource: Resource, density: number): Promise<Uint8Array>
用户
关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回
。
用户
获取指定resource对象对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------- |
| -------- | ---------------------- | ---- | ---- |
| path | string | 是 | rawfile文件路径 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
void
>
| 是 | 异步回调 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------- |
| Promise<Uint8Array> | resource对象对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -1947,41 +1953,41 @@ closeRawFd(path: string, callback: AsyncCallback<void>): void
...
@@ -1947,41 +1953,41 @@ closeRawFd(path: string, callback: AsyncCallback<void>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | The resource not found by path. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
closeRawFd
(
"
test.xml
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.
getMediaContent(resource, 120).then(value
=> {
if
(
error
!=
null
)
{
let media = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
console.error(
`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback closeRawFd
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMediaContent
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
###
closeRawFd
<sup>9+</sup>
###
getMediaByName
<sup>9+</sup>
closeRawFd(path: string): Promise
<
void
>
getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void
用户
关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回
。
用户
获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ----------- |
| -------- | ------------------------------- | ---- | ------------------ |
| path | string | 是 | rawfile文件路径 |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ---- |
| Promise
<
void
>
| 无返回值 |
**错误码:**
**错误码:**
...
@@ -1989,52 +1995,39 @@ closeRawFd(path: string): Promise<void>
...
@@ -1989,52 +1995,39 @@ closeRawFd(path: string): Promise<void>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
closeRawFd
(
"
test.xml
"
).
then
(
value
=>
{
this.context.resourceManager.getMediaByName("test", (error, value) => {
let
result
=
value
;
if (error != null) {
}).
catch
(
error
=>
{
console.log("error is " + error);
console
.
log
(
"
closeRawFd promise error is
"
+
error
);
} else {
let media = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise closeRawFd failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### release<sup>7+</sup>
release()
用户释放创建的resourceManager。
**系统能力**
:SystemCapability.Global.ResourceManager
**示例:**
```
ts
try
{
this
.
context
.
resourceManager
.
release
();
}
catch
(
error
)
{
console
.
error
(
"
release error is
"
+
error
);
}
}
```
```
### get
StringByName<sup>9
+</sup>
### get
MediaByName<sup>10
+</sup>
get
StringByName(resName: string, callback: AsyncCallback
<
string
>
): void
get
MediaByName(resName: string, density: number, callback: AsyncCallback<Uint8Array
>): void
用户获取指定资源
名称对应的字符串,使用callback形式返回字符串
。
用户获取指定资源
ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| -------- | ------------------------------- | ---- | ------------------ |
| resName | string | 是 | 资源名称 |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的字符串 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -2044,32 +2037,31 @@ getStringByName(resName: string, callback: AsyncCallback<string>): void
...
@@ -2044,32 +2037,31 @@ getStringByName(resName: string, callback: AsyncCallback<string>): void
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
StringByName
(
"
test
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.get
MediaByName("test", 120
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
log
(
"
error is
"
+
error
);
console.error(
`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
else
{
} else {
let
string
=
value
;
let media
= value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback get
String
ByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback get
Media
ByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
String
ByName<sup>9+</sup>
### get
Media
ByName<sup>9+</sup>
get
StringByName(resName: string): Promise
<
string
>
get
MediaByName(resName: string): Promise<Uint8Array
>
用户获取指定资源名称对应的
字符串,使用Promise形式返回字符串
。
用户获取指定资源名称对应的
媒体文件内容,使用Promise形式返回字节数组
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| ------- | ------ | ---- | ---- |
...
@@ -2077,9 +2069,9 @@ getStringByName(resName: string): Promise<string>
...
@@ -2077,9 +2069,9 @@ getStringByName(resName: string): Promise<string>
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
|
---------- |
| ---------------------
---- | ---
---------- |
| Promise
<
string
>
| 资源名称对应的字符串
|
| Promise<
Uint8Array> | 资源名称对应的媒体文件内容
|
**错误码:**
**错误码:**
...
@@ -2089,35 +2081,40 @@ getStringByName(resName: string): Promise<string>
...
@@ -2089,35 +2081,40 @@ getStringByName(resName: string): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
get
String
ByName
(
"
test
"
).
then
(
value
=>
{
this.context.resourceManager.get
Media
ByName("test").then(value => {
let
string
=
value
;
let media
= value;
}).catch(error => {
}).catch(error => {
console
.
log
(
"
getString
ByName promise error is
"
+
error
);
console.log("getMedia
ByName promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise get
StringByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise get
MediaByName failed, error code: ${error.code}, message: ${error.message}.`
)
}
}
```
```
### get
StringArrayByName<sup>9
+</sup>
### get
MediaByName<sup>10
+</sup>
get
StringArrayByName(resName: string, callback: AsyncCallback
<
Array
<
string
>>
): void
get
MediaByName(resName: string, density: number): Promise<Uint8Array>
用户获取指定资源名称对应的
字符串数组,使用callback形式返回字符串
数组。
用户获取指定资源名称对应的
指定屏幕密度媒体文件内容,使用Promise形式返回字节
数组。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------------- |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 异步回调,用于返回获取的字符串数组 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------- |
| Promise<Uint8Array> | 资源名称对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -2127,42 +2124,40 @@ getStringArrayByName(resName: string, callback: AsyncCallback<Array<string
...
@@ -2127,42 +2124,40 @@ getStringArrayByName(resName: string, callback: AsyncCallback<Array<string
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringArrayByName
(
"
test
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaByName("test", 120).then(value => {
if
(
error
!=
null
)
{
let media = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
else
{
console.error(
`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`
);
let
strArray
=
value
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getStringArray
ByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMedia
ByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringArrayByName<sup>9
+</sup>
### get
MediaContentBase64Sync<sup>10
+</sup>
get
StringArrayByName(resName: string): Promise
<
Array
<
string
>>
get
MediaContentBase64Sync(resId: number, density?: number): string
用户获取指定资源
名称对应的字符串数组,使用Promise形式返回字符串数组
。
用户获取指定资源
ID对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| ----- | ------ | ---- | ----- |
| resName | string | 是 | 资源名称 |
| resId | number | 是 | 资源ID值 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| --------
-------------------------- | -
----------- |
| --------
|
----------- |
|
Promise
<
Array
<
string
>>
| 资源名称对应的字符串数组
|
|
string | 资源ID对应的图片资源Base64编码
|
**错误码:**
**错误码:**
...
@@ -2170,37 +2165,46 @@ getStringArrayByName(resName: string): Promise<Array<string>>
...
@@ -2170,37 +2165,46 @@ getStringArrayByName(resName: string): Promise<Array<string>>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001001 | If the resId invalid. |
| 9001004 | If the resource not found by resName. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringArrayByName
(
"
test
"
).
then
(
value
=>
{
this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // 默认屏幕密度
let
strArray
=
value
;
}).
catch
(
error
=>
{
console
.
log
(
"
getStringArrayByName promise error is
"
+
error
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise getStringArrayByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // 指定屏幕密度
} catch (error) {
console.error(
`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
ByName<sup>9
+</sup>
### getMedia
ContentBase64Sync<sup>10
+</sup>
getMedia
ByName(resName: string, callback: AsyncCallback
<
Uint8Array
>
): void
getMedia
ContentBase64Sync(resource: Resource, density?: number): string
用户获取指定
资源ID对应的媒体文件内容,使用callback形式返回字节数组
。
用户获取指定
resource对象对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------ |
| ----- | ------ | ---- | ----- |
| resName | string | 是 | 资源名称 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ----------- |
| string | resource对象对应的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2208,39 +2212,43 @@ getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void
...
@@ -2208,39 +2212,43 @@ getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMediaByName
(
"
test
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaContentBase64Sync(resource); // 默认屏幕密度
if
(
error
!=
null
)
{
console
.
log
(
"
error is
"
+
error
);
}
else
{
let
media
=
value
;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getMediaByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // 指定屏幕密度
} catch (error) {
console.error(
`getMediaContentBase64Sync failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
ByName<sup>10
+</sup>
### getMedia
ContentBase64<sup>9
+</sup>
getMedia
ByName(resName: string, density: number, callback: AsyncCallback
<
Uint8Array
>
): void
getMedia
ContentBase64(resId: number, callback: AsyncCallback<string
>): void
用户获取指定资源ID对应的
指定屏幕密度媒体文件内容,使用callback形式返回字节数组
。
用户获取指定资源ID对应的
图片资源Base64编码,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
Content
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------ |
| -------- | --------------------------- | ---- | ------------------------ |
| resName | string | 是 | 资源名称 |
| resId | number | 是 | 资源ID值 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| callback | AsyncCallback
<
Uint8Array
>
| 是 | 异步回调,用于返回获取的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -2248,43 +2256,39 @@ getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint
...
@@ -2248,43 +2256,39 @@ getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMedia
ByName
(
"
test
"
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMedia
ContentBase64($r('app.media.test').id
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
error
(
`callback getMediaByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("error is " + error
);
}
else
{
} else {
let
media
=
value
;
let media = value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getMedia
ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback getMedia
ContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
ByName<sup>9
+</sup>
### getMedia
ContentBase64<sup>10
+</sup>
getMedia
ByName(resName: string): Promise
<
Uint8Array
>
getMedia
ContentBase64(resId: number, density: number, callback: AsyncCallback<string>): void
用户获取指定资源
名称对应的媒体文件内容,使用Promise形式返回字节数组
。
用户获取指定资源
ID对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| -------- | --------------------------- | ---- | ------------------------ |
| resName | string | 是 | 资源名称 |
| resId | number | 是 | 资源ID值 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| 类型 | 说明 |
| ------------------------- | ------------- |
| Promise
<
Uint8Array
>
| 资源名称对应的媒体文件内容 |
**错误码:**
**错误码:**
...
@@ -2292,42 +2296,43 @@ getMediaByName(resName: string): Promise<Uint8Array>
...
@@ -2292,42 +2296,43 @@ getMediaByName(resName: string): Promise<Uint8Array>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMediaByName
(
"
test
"
).
then
(
value
=>
{
this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => {
if (error != null) {
console.error(
`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`
);
} else {
let media = value;
let media = value;
}).
catch
(
error
=>
{
}
console
.
log
(
"
getMediaByName promise error is
"
+
error
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
)
console.error(
`
callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
ByName<sup>10
+</sup>
### getMedia
ContentBase64<sup>9
+</sup>
getMedia
ByName(resName: string, density: number): Promise
<
Uint8Array
>
getMedia
ContentBase64(resId: number): Promise<string
>
用户获取指定资源
名称对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组
。
用户获取指定资源
ID对应的图片资源Base64编码,使用Promise形式返回字符串
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| ----- | ------ | ---- | ----- |
| resName | string | 是 | 资源名称 |
| resId | number | 是 | 资源ID值 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
---- |
------------- |
| ---------------------
| -------
------------- |
| Promise
<
Uint8Array
>
| 资源名称对应的媒体文件内容
|
| Promise<
string> | 资源ID值对应的图片资源Base64编码
|
**错误码:**
**错误码:**
...
@@ -2335,36 +2340,42 @@ getMediaByName(resName: string, density: number): Promise<Uint8Array>
...
@@ -2335,36 +2340,42 @@ getMediaByName(resName: string, density: number): Promise<Uint8Array>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMedia
ByName
(
"
test
"
,
120
).
then
(
value
=>
{
this.context.resourceManager.getMedia
ContentBase64($r('app.media.test').id
).then(value => {
let
media
=
value
;
let media = value;
}).catch(error => {
}).catch(error => {
console
.
error
(
`promise getMediaByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("getMediaContentBase64 promise error is " + error
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise getMedia
ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise getMedia
ContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
Base64ByName<sup>9
+</sup>
### getMedia
ContentBase64<sup>10
+</sup>
getMedia
Base64ByName(resName: string, callback: AsyncCallback
<
string
>
): void
getMedia
ContentBase64(resId: number, density: number): Promise<string>
用户获取指定资源
名称对应的图片资源Base64编码,使用callback
形式返回字符串。
用户获取指定资源
ID对应的指定屏幕密度图片资源Base64编码,使用Promise
形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ |
| ----- | ------ | ---- | ----- |
| resName | string | 是 | 资源名称 |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| 类型 | 说明 |
| --------------------- | -------------------- |
| Promise<string> | 资源ID值对应的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2372,38 +2383,37 @@ getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): vo
...
@@ -2372,38 +2383,37 @@ getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): vo
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getMediaBase64ByName
(
"
test
"
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then(value => {
if
(
error
!=
null
)
{
let media = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
else
{
console.error(
`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`
);
let
media
=
value
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getMediaBase64ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMediaContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
Base64ByName<sup>10
+</sup>
### getMedia
ContentBase64<sup>9
+</sup>
getMedia
Base64ByName(resName: string, density: number
, callback: AsyncCallback
<
string
>
): void
getMedia
ContentBase64(resource: Resource
, callback: AsyncCallback<string>): void
用户获取指定
资源名称对应的指定屏幕密度
图片资源Base64编码,使用callback形式返回字符串。
用户获取指定
resource对象对应的
图片资源Base64编码,使用callback形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ |
| -------- | --------------------------- | ---- | ------------------------ |
| resName | string | 是 | 资源名称 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2412,43 +2422,46 @@ getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback&l
...
@@ -2412,43 +2422,46 @@ getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback&l
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMedia
Base64ByName
(
"
test
"
,
120
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMedia
ContentBase64(resource
, (error, value) => {
if
(
error
!=
null
)
{
if (error != null) {
console
.
error
(
`callback getMediaBase64ByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("error is " + error
);
}
else
{
} else {
let
media
=
value
;
let media = value;
}
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`callback getMedia
Base64ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`callback getMedia
ContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
Base64ByName<sup>9
+</sup>
### getMedia
ContentBase64<sup>10
+</sup>
getMedia
Base64ByName(resName: string): Promise
<
string
>
getMedia
ContentBase64(resource: Resource, density: number, callback: AsyncCallback<string>): void
用户获取指定
资源名称对应的图片资源Base64编码,使用Promise
形式返回字符串。
用户获取指定
resource对象对应的指定屏幕密度图片资源Base64编码,使用callback
形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**模型约束**:此接口仅可在Stage模型下使用。
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
**
返回值
:**
**
参数
:**
| 类型 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| --------------------- | ------------------- |
| -------- | --------------------------- | ---- | ------------------------ |
| Promise
<
string
>
| 资源名称对应的图片资源Base64编码 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2456,42 +2469,50 @@ getMediaBase64ByName(resName: string): Promise<string>
...
@@ -2456,42 +2469,50 @@ getMediaBase64ByName(resName: string): Promise<string>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMediaBase64ByName
(
"
test
"
).
then
(
value
=>
{
this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => {
if (error != null) {
console.error(
`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`
);
} else {
let media = value;
let media = value;
}).
catch
(
error
=>
{
}
console
.
log
(
"
getMediaBase64ByName promise error is
"
+
error
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getMediaBase64ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getMediaContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getMedia
Base64ByName<sup>10
+</sup>
### getMedia
ContentBase64<sup>9
+</sup>
getMedia
Base64ByName(resName: string, density: number
): Promise
<
string
>
getMedia
ContentBase64(resource: Resource
): Promise<string>
用户获取指定
资源名称对应的指定屏幕密度
图片资源Base64编码,使用Promise形式返回字符串。
用户获取指定
resource对象对应的
图片资源Base64编码,使用Promise形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| -------- | ---------------------- | ---- | ---- |
| resName | string | 是 | 资源名称 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
|
[
density
](
#screendensity
)
| number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| --------------------- | ------------------- |
| --------------------- | -------------------
------
|
| Promise
<
string
>
|
资源名称
对应的图片资源Base64编码 |
| Promise<string> |
resource对象
对应的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2499,37 +2520,49 @@ getMediaBase64ByName(resName: string, density: number): Promise<string>
...
@@ -2499,37 +2520,49 @@ getMediaBase64ByName(resName: string, density: number): Promise<string>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 900100
3 | If the resName invalid.
|
| 900100
1 | If the resId invalid.
|
| 900100
4 | If the resource not found by resName.
|
| 900100
2 | If the resource not found by resId.
|
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getMedia
Base64ByName
(
"
test
"
,
120
).
then
(
value
=>
{
this.context.resourceManager.getMedia
ContentBase64(resource
).then(value => {
let
media
=
value
;
let media = value;
}).catch(error => {
}).catch(error => {
console
.
error
(
`promise getMediaBase64ByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.log("getMediaContentBase64 promise error is " + error
);
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`promise getMedia
Base64ByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`promise getMedia
ContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
PluralStringByName<sup>9
+</sup>
### get
MediaContentBase64<sup>10
+</sup>
get
PluralStringByName(resName: string, num: number, callback: AsyncCallback
<
string
>
): void
get
MediaContentBase64(resource: Resource, density: number): Promise<string>
根据传入的数量值,获取资源名称对应的字符串资源,使用callback
形式返回字符串。
用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用Promise
形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ----------------------------- |
| -------- | ---------------------- | ---- | ---- |
| resName | string | 是 | 资源名称 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| num | number | 是 | 数量值 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
| callback | AsyncCallback
<
string
>
| 是 | 异步回调,返回根据传入的数量值获取资源名称对应的字符串资源 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise<string> | resource对象对应的图片资源Base64编码 |
**错误码:**
**错误码:**
...
@@ -2537,46 +2570,41 @@ getPluralStringByName(resName: string, num: number, callback: AsyncCallback<s
...
@@ -2537,46 +2570,41 @@ getPluralStringByName(resName: string, num: number, callback: AsyncCallback<s
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001001 | If the resId invalid. |
| 9001004 | If the resource not found by resName. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
try {
try {
this
.
context
.
resourceManager
.
getPluralStringByName
(
"
test
"
,
1
,
(
error
,
value
)
=>
{
this.context.resourceManager.getMediaContentBase64(resource, 120).then(value => {
if
(
error
!=
null
)
{
let media = value;
console
.
log
(
"
error is
"
+
error
);
}).catch(error => {
}
else
{
console.error(
`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`
);
let
str
=
value
;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
callback getPluralStringByName
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMediaContentBase64
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
PluralString
ByName<sup>9+</sup>
### get
MediaBase64
ByName<sup>9+</sup>
get
PluralStringByName(resName: string, num: number): Promise
<
string
>
get
MediaBase64ByName(resName: string, callback: AsyncCallback<string>): void
根据传入的数量值,获取资源名称对应的字符串资源,使用Promise
形式返回字符串。
用户获取指定资源名称对应的图片资源Base64编码,使用callback
形式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| -------- | --------------------------- | ---- | ------------------------ |
| resName | string | 是 | 资源名称 |
| resName | string | 是 | 资源名称 |
| num | number | 是 | 数量值 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------------- |
| Promise
<
string
>
| 根据传入的数量值获取资源名称对应的字符串资源 |
**错误码:**
**错误码:**
...
@@ -2586,40 +2614,37 @@ getPluralStringByName(resName: string, num: number): Promise<string>
...
@@ -2586,40 +2614,37 @@ getPluralStringByName(resName: string, num: number): Promise<string>
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getPluralStringByName
(
"
test
"
,
1
).
then
(
value
=>
{
this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
let
str
=
value
;
if (error != null) {
}).
catch
(
error
=>
{
console.log("error is " + error);
console
.
log
(
"
getPluralStringByName promise error is
"
+
error
);
} else {
let media = value;
}
});
});
} catch (error) {
} catch (error) {
console
.
error
(
`
promise getPluralString
ByName failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getMediaBase64
ByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringSync<sup>9
+</sup>
### get
MediaBase64ByName<sup>10
+</sup>
get
StringSync(resId: number): string
get
MediaBase64ByName(resName: string, density: number, callback: AsyncCallback<string>): void
用户获取指定资源
ID对应的字符串,使用同步方
式返回字符串。
用户获取指定资源
名称对应的指定屏幕密度图片资源Base64编码,使用callback形
式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| -------- | --------------------------- | ---- | ------------------------ |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的图片资源Base64编码 |
| 类型 | 说明 |
| ------ | ----------- |
| string | 资源ID值对应的字符串 |
**错误码:**
**错误码:**
...
@@ -2627,81 +2652,86 @@ getStringSync(resId: number): string
...
@@ -2627,81 +2652,86 @@ getStringSync(resId: number): string
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringSync
(
$r
(
'
app.string.test
'
).
id
);
this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => {
if (error != null) {
console.error(
`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`
);
} else {
let media = value;
}
});
} catch (error) {
} catch (error) {
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
callback getMediaBase64ByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringSync<sup>10
+</sup>
### get
MediaBase64ByName<sup>9
+</sup>
get
StringSync(resId: number, ...args: Array
<string
|
number
>
): string
get
MediaBase64ByName(resName: string): Promise<string>
用户获取指定资源
ID对应的字符串,根据args参数进行格式化,使用同步方式返回相应
字符串。
用户获取指定资源
名称对应的图片资源Base64编码,使用Promise形式返回
字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ------- | ------ | ---- | ---- |
| resId | number | 是 | 资源ID值 |
| resName | string | 是 | 资源名称 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
-%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
| ---------
------------------- |
| ------
--------------- |
------------------- |
|
string | 资源ID值对应的格式化字符串
|
|
Promise<string> | 资源名称对应的图片资源Base64编码
|
**错误码:**
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ----------------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this
.
context
.
resourceManager
.
getStringSync
(
$r
(
'
app.string.test
'
).
id
,
"
format string
"
,
10
,
98.78
);
this.context.resourceManager.getMediaBase64ByName("test").then(value => {
let media = value;
}).catch(error => {
console.log("getMediaBase64ByName promise error is " + error);
});
} catch (error) {
} catch (error) {
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMediaBase64ByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringSync<sup>9
+</sup>
### get
MediaBase64ByName<sup>10
+</sup>
get
StringSync(resource: Resource): string
get
MediaBase64ByName(resName: string, density: number): Promise<string>
用户获取指定
resource对象对应的字符串,使用同步方
式返回字符串。
用户获取指定
资源名称对应的指定屏幕密度图片资源Base64编码,使用Promise形
式返回字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**
:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| ------- | ------ | ---- | ---- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| resName | string | 是 | 资源名称 |
| [density](#screendensity) | number | 是 | 资源获取需要的屏幕密度,0表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
|
---------------- |
| ------
--------------- | ---
---------------- |
|
string | resource对象对应的字符串
|
|
Promise<string> | 资源名称对应的图片资源Base64编码
|
**错误码:**
**错误码:**
...
@@ -2709,46 +2739,42 @@ getStringSync(resource: Resource): string
...
@@ -2709,46 +2739,42 @@ getStringSync(resource: Resource): string
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001003 | If the resName invalid. |
| 9001002 | If the resource not found by resId. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.string.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
getStringSync
(
resource
);
this.context.resourceManager.getMediaBase64ByName("test", 120).then(value => {
let media = value;
}).catch(error => {
console.error(
`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`
);
});
} catch (error) {
} catch (error) {
console
.
error
(
`
getStringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`
promise getMediaBase64ByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringSync
<sup>10+</sup>
### get
DrawableDescriptor
<sup>10+</sup>
get
StringSync(resource: Resource, ...args: Array
<string
|
number
>
): string
get
DrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
用户获取指定
resource对象对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串
。
用户获取指定
资源ID对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**
模型约束**
:此接口仅可在Stage模型下使用。
**
参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| 参数名 | 类型 | 必填 | 说明 |
| resId | number | 是 | 资源ID值 |
| -------- | ---------------------- | ---- | ---- |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
-%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| ------ | ----------
------------------
|
| ------ | ---------- |
|
string | resource对象对应的格式化字符串
|
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
**错误码:**
**错误码:**
...
@@ -2758,42 +2784,43 @@ getStringSync(resource: Resource, ...args: Array<string | number>): string
...
@@ -2758,42 +2784,43 @@ getStringSync(resource: Resource, ...args: Array<string | number>): string
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
**示例:**
```
ts
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.string.test
'
).
id
};
try {
try {
this
.
context
.
resourceManager
.
get
StringSync
(
resource
,
"
format string
"
,
10
,
98.78
);
this.context.resourceManager.get
DrawableDescriptor($r('app.media.icon').id
);
} catch (error) {
} catch (error) {
console
.
error
(
`get
StringSync
failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
);
console.error(
`get
DrawableDescriptor
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
} catch (error) {
console.error(
`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### get
StringByNameSync<sup>9
+</sup>
### get
DrawableDescriptor<sup>10
+</sup>
get
StringByNameSync(resName: string): string
get
DrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
用户获取指定
资源名称对应的字符串,使用同步方式返回字符串
。
用户获取指定
resource对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**
参数:**
**
模型约束**:此接口仅可在Stage模型下使用。
| 参数名 | 类型 | 必填 | 说明 |
**参数:**
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
|
---------- |
| ------
- | -------
---------- |
|
string | 资源名称对应的字符串
|
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
**错误码:**
**错误码:**
...
@@ -2801,39 +2828,48 @@ getStringByNameSync(resName: string): string
...
@@ -2801,39 +2828,48 @@ getStringByNameSync(resName: string): string
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001001 | If the resId invalid. |
| 9001004 | If the resource not found by resName. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.icon').id
};
try {
try {
this.context.resourceManager.get
StringByNameSync("test"
);
this.context.resourceManager.get
DrawableDescriptor(resource
);
} catch (error) {
} catch (error) {
console.error(
`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getDrawableDescriptor(resource, 120);
} catch (error) {
console.error(
`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
StringByNameSync
<sup>10+</sup>
### get
DrawableDescriptorByName
<sup>10+</sup>
get
StringByNameSync(resName: string, ...args: Array<string | number>): string
get
DrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor;
用户获取指定资源名称对应的
字符串,根据args参数进行格式化,使用同步方式返回相应字符串
。
用户获取指定资源名称对应的
DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| resName | string | 是 | 资源名称 |
|
args | Array<string \| number> | 否 | 格式化字符串资源参数 <br> 支持参数类型:<br /> -%d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串
|
|
[density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度
|
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| ------ | ---------
-------------------
|
| ------ | --------- |
|
string | 资源名称对应的格式化字符串
|
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
**错误码:**
**错误码:**
...
@@ -2843,17 +2879,20 @@ getStringByNameSync(resName: string, ...args: Array<string | number>): string
...
@@ -2843,17 +2879,20 @@ getStringByNameSync(resName: string, ...args: Array<string | number>): string
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
| 9001008 | If the resource obtained by resName formatting error. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.get
StringByNameSync("test", "format string", 10, 98.78
);
this.context.resourceManager.get
DrawableDescriptorByName('icon'
);
} catch (error) {
} catch (error) {
console.error(
`get
StringByNameSync
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`get
DrawableDescriptorByName
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
try {
this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
} catch (error) {
console.error(
`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getBoolean<sup>9+</sup>
### getBoolean<sup>9+</sup>
...
@@ -2928,9 +2967,9 @@ getBoolean(resource: Resource): boolean
...
@@ -2928,9 +2967,9 @@ getBoolean(resource: Resource): boolean
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName: "com.example.myapplication",
bundleName: "com.example.myapplication",
moduleName: "entry",
moduleName: "entry",
id: $r('app.boolean.boolean_test').id
id: $r('app.boolean.boolean_test').id
};
};
try {
try {
this.context.resourceManager.getBoolean(resource);
this.context.resourceManager.getBoolean(resource);
...
@@ -3058,9 +3097,9 @@ getNumber(resource: Resource): number
...
@@ -3058,9 +3097,9 @@ getNumber(resource: Resource): number
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName: "com.example.myapplication",
bundleName: "com.example.myapplication",
moduleName: "entry",
moduleName: "entry",
id: $r('app.integer.integer_test').id
id: $r('app.integer.integer_test').id
};
};
try {
try {
this.context.resourceManager.getNumber(resource);// integer对应返回的是原数值, float对应返回的是真实像素点值
this.context.resourceManager.getNumber(resource);// integer对应返回的是原数值, float对应返回的是真实像素点值
...
@@ -3114,11 +3153,11 @@ getNumberByName(resName: string): number
...
@@ -3114,11 +3153,11 @@ getNumberByName(resName: string): number
}
}
```
```
### get
DrawableDescriptor
<sup>10+</sup>
### get
ColorSync
<sup>10+</sup>
get
DrawableDescriptor(resId: number, density?: number): DrawableDescripto
r;
get
ColorSync(resId: number) : numbe
r;
用户获取指定资源ID对应的
DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
用户获取指定资源ID对应的
颜色值,使用同步方式返回其对应的颜色值
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -3127,13 +3166,12 @@ getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
...
@@ -3127,13 +3166,12 @@ getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,默认为0 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ------ | ---------- |
| ------ | ----------
-
|
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
|
number | 资源ID值对应的颜色值(十进制)
|
**错误码:**
**错误码:**
...
@@ -3143,26 +3181,22 @@ getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
...
@@ -3143,26 +3181,22 @@ getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
this.context.resourceManager.getColorSync($r('app.color.test').id);
} catch (error) {
console.error(
`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
} catch (error) {
} catch (error) {
console.error(
`get
DrawableDescriptor
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`get
ColorSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
DrawableDescriptor
<sup>10+</sup>
### get
ColorSync
<sup>10+</sup>
get
DrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
get
ColorSync(resource: Resource): number
用户获取指定resource对
应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
用户获取指定resource对
象对应的颜色值,使用同步方式返回其对应的颜色值
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -3173,13 +3207,12 @@ getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
...
@@ -3173,13 +3207,12 @@ getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,默认为0 |
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ------
- | -
---------------- |
| ------
|
---------------- |
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
|
number | resource对象对应的颜色值(十进制)
|
**错误码:**
**错误码:**
...
@@ -3189,31 +3222,27 @@ getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
...
@@ -3189,31 +3222,27 @@ getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName: "com.example.myapplication",
bundleName: "com.example.myapplication",
moduleName: "entry",
moduleName: "entry",
id: $r('app.media.icon
').id
id: $r('app.color.test
').id
};
};
try {
try {
this.context.resourceManager.getDrawableDescriptor(resource);
this.context.resourceManager.getColorSync(resource);
} catch (error) {
console.error(
`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getDrawableDescriptor(resource, 120);
} catch (error) {
} catch (error) {
console.error(
`get
DrawableDescriptor
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`get
ColorSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
DrawableDescriptorByName
<sup>10+</sup>
### get
ColorByNameSync
<sup>10+</sup>
get
DrawableDescriptorByName(resName: string, density?: number): DrawableDescripto
r;
get
ColorByNameSync(resName: string) : numbe
r;
用户获取指定资源名称对应的
DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示
。
用户获取指定资源名称对应的
颜色值,使用同步方式返回其对应的颜色值
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
...
@@ -3222,13 +3251,12 @@ getDrawableDescriptorByName(resName: string, density?: number): DrawableDescript
...
@@ -3222,13 +3251,12 @@ getDrawableDescriptorByName(resName: string, density?: number): DrawableDescript
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| resName | string | 是 | 资源名称 |
| [density](#screendensity) | number | 否 | 资源获取需要的屏幕密度,默认为0 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ------ | --------- |
| ------ | ---------
-
|
|
DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象
|
|
number | 资源名称对应的颜色值(十进制)
|
**错误码:**
**错误码:**
...
@@ -3238,18 +3266,14 @@ getDrawableDescriptorByName(resName: string, density?: number): DrawableDescript
...
@@ -3238,18 +3266,14 @@ getDrawableDescriptorByName(resName: string, density?: number): DrawableDescript
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.getDrawableDescriptorByName('icon');
this.context.resourceManager.getColorByNameSync("test");
} catch (error) {
console.error(
`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
try {
this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
} catch (error) {
} catch (error) {
console.error(
`get
DrawableDescriptorByName
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`get
ColorByNameSync
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
...
@@ -3280,17 +3304,17 @@ getColor(resId: number, callback: AsyncCallback<number>): void;
...
@@ -3280,17 +3304,17 @@ getColor(resId: number, callback: AsyncCallback<number>): void;
**示例Stage:**
**示例Stage:**
```
ts
```
ts
try {
try {
this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
if (error != null) {
if (error != null) {
console.log("error is " + error);
console.log("error is " + error);
} else {
} else {
let str = value;
let str = value;
}
}
});
});
} catch (error) {
} catch (error) {
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getColor<sup>10+</sup>
### getColor<sup>10+</sup>
...
@@ -3327,9 +3351,9 @@ getColor(resId: number): Promise<number>
...
@@ -3327,9 +3351,9 @@ getColor(resId: number): Promise<number>
```
ts
```
ts
try {
try {
this.context.resourceManager.getColor($r('app.color.test').id).then(value => {
this.context.resourceManager.getColor($r('app.color.test').id).then(value => {
let str = value;
let str = value;
}).catch(error => {
}).catch(error => {
console.log("getColor promise error is " + error);
console.log("getColor promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console.error(
`promise getColor failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`promise getColor failed, error code: ${error.code}, message: ${error.message}.`
);
...
@@ -3366,44 +3390,373 @@ getColor(resource: Resource, callback: AsyncCallback<number>): void;
...
@@ -3366,44 +3390,373 @@ getColor(resource: Resource, callback: AsyncCallback<number>): void;
**示例:**
**示例:**
```
ts
```
ts
let resource = {
let resource = {
bundleName: "com.example.myapplication",
bundleName: "com.example.myapplication",
moduleName: "entry",
moduleName: "entry",
id: $r('app.color.test').id
id: $r('app.color.test').id
};
};
try {
try {
this.context.resourceManager.getColor(resource, (error, value) => {
this.context.resourceManager.getColor(resource, (error, value) => {
if (error != null) {
if (error != null) {
console.log("error is " + error);
console.log("error is " + error);
} else {
} else {
let str = value;
let str = value;
}
}
});
} catch (error) {
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getColor<sup>10+</sup>
getColor(resource: Resource): Promise<number>;
用户获取指定resource对象对应的颜色值,使用Promise形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise<number> | resource对象对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
this.context.resourceManager.getColor(resource).then(value => {
let str = value;
}).catch(error => {
console.log("getColor promise error is " + error);
});
} catch (error) {
console.error(
`promise getColor failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getColorByName<sup>10+</sup>
getColorByName(resName: string, callback: AsyncCallback<number>): void
用户获取指定资源名称对应的颜色值,使用callback形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback<number> | 是 | 异步回调,用于返回获取的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorByName("test", (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let string = value;
}
});
} catch (error) {
console.error(
`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getColorByName<sup>10+</sup>
getColorByName(resName: string): Promise<number>
用户获取指定资源名称对应的颜色值,使用Promise形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------- |
| Promise<number> | 资源名称对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorByName("test").then(value => {
let string = value;
}).catch(error => {
console.log("getColorByName promise error is " + error);
});
} catch (error) {
console.error(
`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getRawFileContent<sup>9+</sup>
getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void
用户获取resources/rawfile目录下对应的rawfile文件内容,使用callback形式返回字节数组。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ----------------------- |
| path | string | 是 | rawfile文件路径 |
| callback | AsyncCallback<Uint8Array> | 是 | 异步回调,用于返回获取的rawfile文件内容 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
**示例:**
```
ts
try {
this.context.resourceManager.getRawFileContent("test.xml", (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let rawFile = value;
}
});
} catch (error) {
console.error(
`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getRawFileContent<sup>9+</sup>
getRawFileContent(path: string): Promise<Uint8Array>
用户获取resources/rawfile目录下对应的rawfile文件内容,使用Promise形式返回字节数组。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ----------- |
| path | string | 是 | rawfile文件路径 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ----------- |
| Promise<Uint8Array> | rawfile文件内容 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
**示例:**
```
ts
try {
this.context.resourceManager.getRawFileContent("test.xml").then(value => {
let rawFile = value;
}).catch(error => {
console.log("getRawFileContent promise error is " + error);
});
} catch (error) {
console.error(
`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getRawFileList<sup>10+</sup>
getRawFileList(path: string, callback: AsyncCallback<Array\<string\>>): void;
用户获取resources/rawfile目录下文件夹及文件列表,使用callback形式返回文件列表的字符串数组。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ----------------------- |
| path | string | 是 | rawfile文件夹路径 |
| callback | AsyncCallback<Array\<string\>> | 是 | 异步回调,用于返回获取rawfile文件目录下的文件列表 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
**示例:**
```
ts
try { // 传入""表示获取rawfile根目录下的文件列表
this.context.resourceManager.getRawFileList("", (error, value) => {
if (error != null) {
console.error(
`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`
);
} else {
let rawFile = value;
}
});
} catch (error) {
console.error(
`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getRawFileList<sup>10+</sup>
getRawFileList(path: string): Promise<Array\<string\>>
用户获取resources/rawfile目录下文件夹及文件列表,使用Promise形式返回文件列表字符串数组。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ----------- |
| path | string | 是 | rawfile文件夹路径 |
**返回值:**
| 类型 | 说明 |
| ------------------------- | ----------- |
| Promise<Array\<string\>> | rawfile文件目录下的文件列表 |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
**示例:**
```
ts
try { // 传入""表示获取rawfile根目录下的文件列表
this.context.resourceManager.getRawFileList("").then(value => {
let rawFile = value;
}).catch(error => {
console.error(
`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`
);
});
} catch (error) {
console.error(
`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`
);
}
```
### getRawFd<sup>9+</sup>
getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void
用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path | string | 是 | rawfile文件路径 |
| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | 是 | 异步回调,用于返回获取的rawfile文件的descriptor |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001005 | If the resource not found by path. |
**示例:**
```
ts
try {
this.context.resourceManager.getRawFd("test.xml", (error, value) => {
if (error != null) {
console.log(
`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`
);
} else {
let fd = value.fd;
let offset = value.offset;
let length = value.length;
}
});
});
} catch (error) {
} catch (error) {
console.error(
`callback get
Color
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`callback get
RawFd
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### get
Color<sup>10
+</sup>
### get
RawFd<sup>9
+</sup>
get
Color(resource: Resource): Promise<number>
;
get
RawFd(path: string): Promise<RawFileDescriptor>
;
用户获取
指定resource对象对应的颜色值,使用Promise形式返回其对应的颜色值
。
用户获取
resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**模型约束**:此接口仅可在Stage模型下使用。
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| ----
---- | ---------------------- | ---- |
---- |
| ----
| ------ | ---- | -------
---- |
|
resource | [Resource](#resource9) | 是 | 资源信息
|
|
path | string | 是 | rawfile文件路径
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ---------------------
|
---------------- |
| ---------------------
------------------- | ---
---------------- |
| Promise<
number> | resource对象对应的颜色值(十进制)
|
| Promise<
[RawFileDescriptor](#rawfiledescriptor8)> | rawfile文件descriptor
|
**错误码:**
**错误码:**
...
@@ -3411,42 +3764,37 @@ getColor(resource: Resource): Promise<number>;
...
@@ -3411,42 +3764,37 @@ getColor(resource: Resource): Promise<number>;
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001005 | If the resource not found by path. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
try {
this.context.resourceManager.getColor(resource).then(value => {
this.context.resourceManager.getRawFd("test.xml").then(value => {
let str = value;
let fd = value.fd;
let offset = value.offset;
let length = value.length;
}).catch(error => {
}).catch(error => {
console.log(
"getColor promise error is " + error
);
console.log(
`promise getRawFd error error code: ${error.code}, message: ${error.message}.`
);
});
});
} catch (error) {
} catch (error) {
console.error(
`promise get
Color
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`promise get
RawFd
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
###
getColorByName<sup>10
+</sup>
###
closeRawFd<sup>9
+</sup>
getColorByName(resName: string, callback: AsyncCallback<number
>): void
closeRawFd(path: string, callback: AsyncCallback<void
>): void
用户
获取指定资源名称对应的颜色值,使用callback形式返回其对应的颜色值
。
用户
关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型
| 必填 | 说明
|
| 参数名 | 类型
| 必填 | 说明
|
| -------- | -------------------------
-- | ---- | ----
----------- |
| -------- | -------------------------
| ---- |
----------- |
|
resName | string | 是 | 资源名称
|
|
path | string | 是 | rawfile文件路径
|
| callback | AsyncCallback<
number> | 是 | 异步回调,用于返回获取的颜色值(十进制)
|
| callback | AsyncCallback<
void> | 是 | 异步回调
|
**错误码:**
**错误码:**
...
@@ -3454,44 +3802,40 @@ getColorByName(resName: string, callback: AsyncCallback<number>): void
...
@@ -3454,44 +3802,40 @@ getColorByName(resName: string, callback: AsyncCallback<number>): void
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001005 | The resource not found by path. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.getColorByName("test", (error, value) => {
this.context.resourceManager.closeRawFd("test.xml", (error, value) => {
if (error != null) {
if (error != null) {
console.log("error is " + error);
console.log("error is " + error);
} else {
}
let string = value;
}
});
});
} catch (error) {
} catch (error) {
console.error(
`callback
getColorByName
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`callback
closeRawFd
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
###
getColorByName<sup>10
+</sup>
###
closeRawFd<sup>9
+</sup>
getColorByName(resName: string): Promise<number
>
closeRawFd(path: string): Promise<void
>
用户
获取指定资源名称对应的颜色值,使用Promise形式返回其对应的颜色值
。
用户
关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名
| 类型 | 必填 | 说明
|
| 参数名
| 类型 | 必填 | 说明
|
| ----
--- | ------ | ---- |
---- |
| ----
| ------ | ---- | -------
---- |
|
resName | string | 是 | 资源名称
|
|
path | string | 是 | rawfile文件路径
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| -------------------
-- | ------
---- |
| -------------------
|
---- |
| Promise<
number> | 资源名称对应的颜色值(十进制)
|
| Promise<
void> | 无返回值
|
**错误码:**
**错误码:**
...
@@ -3499,144 +3843,151 @@ getColorByName(resName: string): Promise<number>
...
@@ -3499,144 +3843,151 @@ getColorByName(resName: string): Promise<number>
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001005 | If the resource not found by path. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.
getColorByName("test
").then(value => {
this.context.resourceManager.
closeRawFd("test.xml
").then(value => {
let string
= value;
let result
= value;
}).catch(error => {
}).catch(error => {
console.log("getColorByName
promise error is " + error);
console.log("closeRawFd
promise error is " + error);
});
});
} catch (error) {
} catch (error) {
console.error(
`promise
getColorByName
failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`promise
closeRawFd
failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
### getCo
lorSync<sup>10+</sup>
### getCo
nfiguration
getCo
lorSync(resId: number) : number;
getCo
nfiguration(callback: AsyncCallback<Configuration>): void
用户获取
指定资源ID对应的颜色值,使用同步方式返回其对应的颜色值
。
用户获取
设备的Configuration,使用callback形式返回Configuration对象
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
**返回值:**
| 类型 | 说明 |
| ------ | ----------- |
| number | 资源ID值对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- |
| -------- | ---------------------------------------- | ---- | ------------------------- |
| 9001001 | If the resId invalid. |
| callback | AsyncCallback<[Configuration](#configuration)> | 是 | 异步回调,用于返回设备的Configuration |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.getColorSync($r('app.color.test').id);
this.context.resourceManager.getConfiguration((error, value) => {
if (error != null) {
console.error("getConfiguration callback error is " + error);
} else {
let direction = value.direction;
let locale = value.locale;
}
});
} catch (error) {
} catch (error) {
console.error(
`getColorSync failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
"getConfiguration callback error is " + error
);
}
}
```
```
### getCo
lorSync<sup>10+</sup>
### getCo
nfiguration
getCo
lorSync(resource: Resource): number
getCo
nfiguration(): Promise<Configuration>
用户获取
指定resource对象对应的颜色值,使用同步方式返回其对应的颜色值
。
用户获取
设备的Configuration,使用Promise形式返回Configuration对象
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**
模型约束**:此接口仅可在Stage模型下使用。
**
返回值:**
**参数:**
| 类型 | 说明 |
| ---------------------------------------- | ---------------- |
| Promise<[Configuration](#configuration)> | 设备的Configuration |
| 参数名 | 类型 | 必填 | 说明 |
**示例:**
| -------- | ---------------------- | ---- | ---- |
```
ts
| resource | [Resource](#resource9) | 是 | 资源信息 |
try {
this.context.resourceManager.getConfiguration().then(value => {
let direction = value.direction;
let locale = value.locale;
}).catch(error => {
console.error("getConfiguration promise error is " + error);
});
} catch (error) {
console.error("getConfiguration promise error is " + error);
}
```
**返回值:**
### getDeviceCapability
| 类型 | 说明 |
getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void
| ------ | ---------------- |
| number | resource对象对应的颜色值(十进制) |
**错误码:**
用户获取设备的DeviceCapability,使用callback形式返回DeviceCapability对象。
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
**系统能力**:SystemCapability.Global.ResourceManager
| 错误码ID | 错误信息 |
**参数:**
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | 是 | 异步回调,用于返回设备的DeviceCapability |
**示例:**
```
ts
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
try {
this.context.resourceManager.getColorSync(resource);
this.context.resourceManager.getDeviceCapability((error, value) => {
if (error != null) {
console.error("getDeviceCapability callback error is " + error);
} else {
let screenDensity = value.screenDensity;
let deviceType = value.deviceType;
}
});
} catch (error) {
} catch (error) {
console.error(
`getColorSync failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
"getDeviceCapability callback error is " + error
);
}
}
```
```
### get
ColorByNameSync<sup>10+</sup>
### get
DeviceCapability
get
ColorByNameSync(resName: string) : number
;
get
DeviceCapability(): Promise<DeviceCapability>
;
用户获取
指定资源名称对应的颜色值,使用同步方式返回其对应的颜色值
。
用户获取
设备的DeviceCapability,使用Promise形式返回DeviceCapability对象
。
**系统能力**:SystemCapability.Global.ResourceManager
**系统能力**:SystemCapability.Global.ResourceManager
**
参数
:**
**
返回值
:**
|
参数名 | 类型 | 必填 | 说明
|
|
类型 | 说明
|
| -------
| ------ | ---- |
---- |
| -------
--------------------------------- | ---------------
---- |
|
resName | string | 是 | 资源名称
|
|
Promise<[DeviceCapability](#devicecapability)> | 设备的DeviceCapability
|
**返回值:**
**示例:**
```
ts
try {
this.context.resourceManager.getDeviceCapability().then(value => {
let screenDensity = value.screenDensity;
let deviceType = value.deviceType;
}).catch(error => {
console.error("getDeviceCapability promise error is " + error);
});
} catch (error) {
console.error("getDeviceCapability promise error is " + error);
}
```
| 类型 | 说明 |
### release<sup>7+</sup>
| ------ | ---------- |
| number | 资源名称对应的颜色值(十进制) |
**错误码:**
release()
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)
。
用户释放创建的resourceManager
。
| 错误码ID | 错误信息 |
**系统能力**:SystemCapability.Global.ResourceManager
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
**示例:**
```
ts
```
ts
try {
try {
this.context.resourceManager.
getColorByNameSync("test"
);
this.context.resourceManager.
release(
);
} catch (error) {
} catch (error) {
console.error(
`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
"release error is " + error
);
}
}
```
```
...
@@ -3666,9 +4017,9 @@ addResource(path: string) : void;
...
@@ -3666,9 +4017,9 @@ addResource(path: string) : void;
```
ts
```
ts
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
try {
try {
this.context.resourceManager.addResource(path);
this.context.resourceManager.addResource(path);
} catch (error) {
} catch (error) {
console.error(
`addResource failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`addResource failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
...
@@ -3698,9 +4049,9 @@ removeResource(path: string) : void;
...
@@ -3698,9 +4049,9 @@ removeResource(path: string) : void;
```
ts
```
ts
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
try {
try {
this.resmgr.removeResource(path);
this.resmgr.removeResource(path);
} catch (error) {
} catch (error) {
console.error(
`removeResource failed, error code: ${error.code}, message: ${error.message}.`
);
console.error(
`removeResource failed, error code: ${error.code}, message: ${error.message}.`
);
}
}
```
```
...
@@ -3721,7 +4072,7 @@ getString(resId: number, callback: AsyncCallback<string>): void
...
@@ -3721,7 +4072,7 @@ getString(resId: number, callback: AsyncCallback<string>): void
| resId | number | 是 | 资源ID值 |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的字符串 |
| callback | AsyncCallback<string> | 是 | 异步回调,用于返回获取的字符串 |
**示例:**
**示例:**
```
ts
```
ts
resourceManager.getResourceManager((error, mgr) => {
resourceManager.getResourceManager((error, mgr) => {
mgr.getString($r('app.string.test').id, (error, value) => {
mgr.getString($r('app.string.test').id, (error, value) => {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录