隐私管理服务为使用标准化隐私声明托管服务的元服务提供隐私签署状态查询。
元服务在跳转至业务页面时打开蒙层效果,当点击“同意”后,通过监听隐私弹框事件,依据返回结果决定蒙层显示/隐藏。
针对未上架应用市场的元服务接入隐私服务,可以通过手动预置隐私链接信息模拟接入隐私托管和隐私管理服务。预置隐私链接信息完成后,打开应用会弹出统一隐私弹框,通过@ohos.commonEventManager(公共事件)获取隐私弹框签署结果,依据返回结果决定蒙层显示/隐藏。
在运行以下demo时,若首次在真机上运行时未弹出系统隐私授权弹窗,属于正常现象。
原因:隐私链接需先从云测请求获取链接信息,若未配置,再从本地获取预置链接信息,而该请求响应时间超过元服务安装完成时间,导致授权弹窗未能及时触发。
解决方案:可先退出当前元服务,重新进入,系统将重新触发隐私授权流程,可正常弹出。此情况正式上架后不会出现。
若重新进入未正常弹出,需要获取相应日志做进一步分析,具体操作如下:
字段名称 | 字段解释 | 是否必填 |
|---|---|---|
appgallery_privacy_hosted | 是否启用隐私弹框,1表示启用,其他值均表示不启用 | 是 |
appgallery_privacy_link_privacy_statement | 隐私协议url(https),在隐私弹框中作为隐私协议的内容 | 是 |
appgallery_privacy_link_user_agreement | 用户协议url(https),在隐私弹框中作为用户协议的内容 | 否 |
appgallery_privacy_link_user_agreements | 多个用户协议url(https),在隐私弹框中作为多个用户协议的内容。 该值直接引用一个json文件,json文件存放在module的type为entry模块的resources/rawfile文件夹下。 有多个用户协议链接时,优先取appgallery_privacy_link_user_agreements字段,appgallery_privacy_link_user_agreement配置的单个用户协议链接无效。 起始版本:5.0.2(14)。 | 否 |
"metadata": [
{
"name": "appgallery_privacy_hosted", // 是否启用隐私弹框,1表示启用,其他值均表示不启用
"value": "1"
},
{
"name": "appgallery_privacy_link_privacy_statement", // 隐私协议url(https),在隐私弹框中作为隐私协议的内容
"value": "https://www.example.com/" // 必须是https网址
},
{
"name": "appgallery_privacy_link_user_agreement", // 用户协议url(https),在隐私弹框中作为用户协议的内容
"value":"https://www.example.com/" // 必须是https网址
},
{
"name": "appgallery_privacy_link_user_agreements", // 注意使用时单个和多个
"value": "link_user_agreements.json" // 配置json文件名称,示例配置见下文
}
], link_user_agreements.json示例配置:
{
"user_agreement_Infos": [
{
"name": "用户协议1",
"url": "https://xxxx"
},
{
"name": "用户协议2",
"url": "https://xxxx"
}
]
} 接口 | 区别 |
|---|---|
为当前组件添加内容模糊效果,入参为模糊样式。 | |
为当前组件添加内容模糊效果,入参为模糊半径。 | |
为当前组件添加背景模糊效果,入参为模糊样式。 | |
为当前组件添加背景模糊效果,入参为模糊半径。 | |
为当前组件添加背景模糊效果,入参为模糊半径。 |
事件名称 | 值 | 描述 |
|---|---|---|
usual.event.PRIVACY_STATE_CHANGED | 隐私弹框签署结果公共事件,事件携带数据如下: { 'resultType': privacyResultType, 'appIndex': appIndex } 其中: privacyResultType: 1:同意完整模式 0:未同意 appIndex:分身索引 |
import { privacyManager } from '@kit.AppGalleryKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { commonEventManager } from '@kit.BasicServicesKit';
const TAG = 'PrivacySubscribe';
class PrivacySubscribeSample {
private readonly eventId = 'usual.event.PRIVACY_STATE_CHANGED';
// 订阅者信息, 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
private subscriber: commonEventManager.CommonEventSubscriber | undefined = undefined;
// 事件列表
private subscribeInfo: commonEventManager.CommonEventSubscribeInfo = {
events: [this.eventId]
};
// 模糊状态
BlurStyle = BlurStyle.Thin;
public subscribe(): void {
hilog.info(0, TAG, 'subscribe');
// 创建订阅者
commonEventManager.createSubscriber(this.subscribeInfo).then((commonEventSubscriber) => {
this.subscriber = commonEventSubscriber;
// 订阅公共事件
try {
commonEventManager.subscribe(this.subscriber, (err, data) => {
// 当公共事件订阅成功后,事件触发时执行的回调函数
if (err) {
hilog.error(0, TAG, `subscribe failed, code is ${err?.code}, message is ${err?.message}`);
return;
}
let result = JSON.parse(data?.data ?? '{}')?.resultType as number;
if (result === 1) {
// 隐私同意处理
this.BlurStyle = BlurStyle.NONE;
} else {
this.BlurStyle = BlurStyle.Thin;
}
});
} catch (error) {
hilog.error(0, TAG,
`init createSubscriber failed, exception code: ${error.code}`);
}
});
}
}
@Entry
@Component
struct startPage {
message: string = 'Hello World';
@State privacySubscribeSample: PrivacySubscribeSample = new PrivacySubscribeSample();
onPageShow(): void {
this.getPrivacyResults();
this.privacySubscribeSample.subscribe();
}
// 获取隐私协议签署状态
getPrivacyResults() {
try {
// 隐私签署结果类型有三个:0-->不同意隐私协议; 1-->同意完整模式; 2-->协议发生变更,需要重新签署协议
let appPrivacyResults: privacyManager.AppPrivacyResult[] = privacyManager.getAppPrivacyResult();
if (appPrivacyResults.length > 0 && appPrivacyResults[0].result === 1) {
// 同意签署关闭
this.privacySubscribeSample.BlurStyle = BlurStyle.NONE;
} else {
this.privacySubscribeSample.BlurStyle = BlurStyle.Thin;
}
} catch (error) {
console.error('TAG',
`GetAppPrivacyResultPublic exception code:${error.code}`);
}
}
onBackPress() {
// 阻止手动返回
return true;
}
build() {
Stack() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold);
};
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('100%')
.foregroundBlurStyle(this.privacySubscribeSample.BlurStyle,
{ colorMode: ThemeColorMode.LIGHT, adaptiveColor: AdaptiveColor.DEFAULT, scale: 1.0 });
};
}
} 效果图如下:

Q:系统隐私弹框是否可以自定义样式?
A:不可以,为了统一用户体验并使上架审核过程更加高效和省心,元服务须接入平台的隐私托管服务,由平台统一向用户展示隐私协议弹窗。
Q:隐私协议变更自动弹框,还是需要自行处理?
A:若协议被在架版本关联,编辑后需要提交。提交时,系统会提示您是否需要进行弹框明示用户重新获取授权。若选择“是”,待更新的协议审核通过后,用户在使用应用时,将收到弹窗提示隐私政策发生了变化;若选择“否”,则无弹窗。详细参考编辑隐私声明。