讨论广场 问答详情
如何让应用获取通知权限而不需要显示弹出通知?
柳翔天 2026-08-11 14:31:52
90 评论 分享

系统的预装应用。OHOS v5.1.0

90 评论 分享
写回答
全部评论(7)

有个比较粗暴的办法:通知是在仓库applications/standard/permission_manager中弹出的,具体在src/main/ets/pages/dialogPlus.ets中,你在里面建个白名单,发现在白名单就直接授权。我的是6.1 lts的系统,你5.1.0的区别应该不大。补丁大约是下面这样:

diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets
index 8ce5afb..7537b46 100644
--- a/permissionmanager/src/main/ets/pages/dialogPlus.ets
+++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets
@@ -240,7 +240,20 @@ struct dialogPlusPage {

   aboutToAppear() {
     this.viewModel.processIntent(new GrantDialogIntent.InitIntent(this.context)).then(result => {
-      this.dialogController?.open();
+      let bundleName: string = this.callerAppInfo.bundleName;
+      let whiteList: string[] = [
+        'ohos.samples.distributedcalc',
+        'ohos.samples.audio'
+      ];
+      let isInWhiteList: boolean = whiteList.includes(bundleName) || bundleName.startsWith('com.keytop');
+      if (isInWhiteList) {
+        Log.info(`Auto grant permissions for whitelist app: ${bundleName}`);
+        this.autoGrantAll();
+      } else {
+        this.dialogController?.open();
+      }
     })
     this.context.eventHub.on('refresh', () => {
       this.refreshData();
@@ -248,6 +261,17 @@ struct dialogPlusPage {
     this.resourceChangeObserver.register(this.refreshData);
   }

+  async autoGrantAll(): Promise<void> {
+    for (let i = 0; i < this.viewState.grantGroups.length; i++) {
+      let group: PermissionGroupConfig = this.viewState.grantGroups[i];
+      this.viewState.curIndex = i;
+      await this.viewModel.processIntent(
+        new GrantDialogIntent.ClickIntent(this.context, group, this.callerAppInfo, ButtonStatus.ALLOW)
+      );
+    }
+    this.context.terminateSelf();
+  }
+
   aboutToDisappear() {
     this.dialogController = null;
     this.context.eventHub.off('refresh');

 

1
2026-08-15 15:38:55
2026-08-15 15:46:28
然后你把自己的应用加进去&#xff0c;就正常的申请权限&#xff0c;窗口就弹不出来了。
2026-08-15 15:46:28
3 楼

应该说明你当前使用的openharmony版本信息...

我曾在openharmony 4.0 release实现隐藏默认用户授权弹框,通过白名单配置文件来授权,简单讲讲实现方案:

1.内置白名单文件,其中配置各组需要默认授权的包名+sha256 fingerprint

//applications_whitelist.json
[
    {
        "bundleName" : "com.ohos.demo",
        "sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
    },
    {
        "bundleName" : "com.xxx.xxx",
        "sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
    },
    {
        "bundleName" : "com.ohos.camera",
        "sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
    },
    {
        "bundleName" : "com.ohos.photos",
        "sha256_fingerprint": "9AED2A79925ECA050CD2BB9D2A7F694E49E5E135D28EBDCE53836DE76B5080ED"
    }
]

2.修改application/standard/permission_manager/permissionmanager/src/main/ets/pages/dialogPlus.ets

改变授权逻辑(不再显示授权确认弹框),通过添加的bundleAuthorization白名单授权类对应用进行授权

aboutToAppear() {
    win = this.win
    want = this.want

    //Patch Start
    bundleAuthorization.grantBundleViaWhiteList(this.want)
    //this.privacyDialogController.open();
    //Patch End
  }

3.新增bundleAuthorization白名单授权类,对应用进行授权,应用包名+sha256 fingerprint匹配上则授予权限

后续直接修改白名单配置文件控制系统应用或第三方应用授权

1
2026-08-11 15:45:28
2 楼

需要添加预授权,可以把板子里的system/etc/app/下的install_list_permissions.json文件导出来,找到你对应的系统预装应用的包名,在权限列表中permissions配置下相关权限。

2026-08-11 14:55:42
2026-08-13 09:55:03
通知权限不在这里配置。
2026-08-13 09:55:03

vendor\hihope\rk3568\preinstall-config\install_list_permissions.json 在这个文件里配置一下应该就行了

2026-08-11 14:46:14
2026-08-13 09:55:09
通知权限不在这里配置。
2026-08-13 09:55:09