數(shù)據(jù)標簽
該模塊提供文件數(shù)據(jù)安全等級的相關(guān)功能:向應(yīng)用程序提供查詢、設(shè)置文件數(shù)據(jù)安全等級的JS接口。
說明: 本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。 開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[
gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
導(dǎo)入模塊
import securityLabel from '@ohos.securityLabel';
使用說明
使用該功能模塊對文件/目錄進行操作前,需要先獲取其應(yīng)用沙箱路徑,獲取方式及其接口用法請參考:
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = '';
context.getFilesDir().then((data) = > {
path = data;
})
securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel):Promise
以異步方法設(shè)置數(shù)據(jù)標簽,以promise形式返回結(jié)果。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
type | dataLevel | 是 | 文件等級屬性,只支持"s0","s1","s2","s3","s4" |
返回值:
類型 | 說明 |
---|---|
Promise | Promise實例,用于異步獲取結(jié)果。本調(diào)用將返回空值。 |
示例:
let type = "s4";
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
});
securityLabel.setSecurityLabel
setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback):void
以異步方法設(shè)置數(shù)據(jù)標簽,以callback形式返回結(jié)果。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
type | dataLevel | 是 | 文件等級屬性,只支持"s0","s1","s2","s3","s4" |
callback | AsyncCallback | 是 | 是否設(shè)置數(shù)據(jù)標簽之后的回調(diào) |
示例:
let type = "s4";
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, type:dataLevel):void
以同步方法設(shè)置數(shù)據(jù)標簽。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
type | dataLevel | 是 | 文件等級屬性,只支持"s0","s1","s2","s3","s4" |
示例:
let type = "s4";
securityLabel.setSecurityLabelSync(path, type);
securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise
異步方法獲取數(shù)據(jù)標簽,以promise形式返回結(jié)果。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
返回值:
類型 | 說明 |
---|---|
Promise | 返回數(shù)據(jù)標簽 |
示例:
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){
console.log("getSecurityLabel failed with error:" + error);
});
securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback): void
異步方法獲取數(shù)據(jù)標簽,以callback形式返回結(jié)果。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
callback | AsyncCallback | 是 | 異步獲取數(shù)據(jù)標簽之后的回調(diào) |
示例:
let type = "s4";
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type);
});
securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
以同步方法獲取數(shù)據(jù)標簽。
系統(tǒng)能力 :SystemCapability.FileManagement.File.FileIO
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
path | string | 是 | 文件路徑 |
返回值:
類型 | 說明 |
---|---|
string | 返回數(shù)據(jù)標簽HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
示例:
let result = securityLabel.getSecurityLabelSync(path);
console.log("getSecurityLabel successfully:" + result);
審核編輯 黃宇
-
接口
+關(guān)注
關(guān)注
33文章
8885瀏覽量
152999 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2469瀏覽量
43655
發(fā)布評論請先 登錄
相關(guān)推薦
鴻蒙原生應(yīng)用開發(fā)-網(wǎng)絡(luò)管理模塊總述
labview實時標簽打印條碼打印
esp8266收發(fā)文件中的接收固件該怎么處理呢?
《鴻蒙設(shè)備學(xué)習(xí)菜鳥指南》之 【五、搭建開發(fā)環(huán)境】
在網(wǎng)頁遠程前面板中,觸發(fā)文件對話框子VI沒有反應(yīng) 要怎么解決
嵌入式linux系統(tǒng)開發(fā)文件類型
鴻蒙開發(fā)實戰(zhàn):【文件管理】

鴻蒙開發(fā)文件管理:【@ohos.fileManager (公共文件訪問與管理)】

鴻蒙開發(fā)文件管理:【@ohos.statfs (statfs)】

鴻蒙開發(fā)文件管理:【@ohos.storageStatistics (應(yīng)用空間統(tǒng)計)】

鴻蒙開發(fā)文件管理:【@ohos.volumeManager (卷管理)】

評論