HarmonyOS 鸿蒙Next notificationManager.publish无效

发布于 1周前 作者 vueper 来自 鸿蒙OS

HarmonyOS 鸿蒙Next notificationManager.publish无效

总提示Failed to publish notification. Code is 1600004, message is Notification is not enabled

不知道什么原因导致的

HarmonyOS SDK API 9

下面是代码

import router from ‘@ohos.router’;
import MyComponent2 from ‘…/components/MyComponent2’
import display from ‘@ohos.display’;
import promptAction from ‘@ohos.promptAction’;
import notificationManager from ‘@ohos.notificationManager’;
import getPixelMap from ‘…/utils/DecodeUtil’;
import image from ‘@ohos.multimedia.image’;

@Entry @Component struct Index { pageContent?: Object; @Provide pixelMap?: image.PixelMap = undefined;

onPageShow() { this.pageContent = this; this.pixelInit() }

pixelInit () { if (this.pageContent !== undefined){ getPixelMap(this.pageContent).then((pixelMap?: image.PixelMap) => { if (pixelMap) { this.pixelMap = pixelMap; } }) } }

onClickBtn() { console.log(‘zsf this.’, this); getPixelMap(this.pageContent).then((pixelMap?: image.PixelMap) => { if (pixelMap) { this.pixelMap = pixelMap;

    console.log(<span class="hljs-string">'zsf 进来了可'</span>);

    <span class="hljs-keyword">let</span> notificationRequest: notificationManager.NotificationRequest = {
      id: <span class="hljs-number">1</span>,
      content: {
        contentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE,
        picture: {
          title: <span class="hljs-string">'test_title'</span>,
          text: <span class="hljs-string">'test_text'</span>,
          additionalText: <span class="hljs-string">'test_additionalText'</span>,
          briefText: <span class="hljs-string">'test_briefText'</span>,
          expandedTitle: <span class="hljs-string">'test_expandedTitle'</span>,
          picture: <span class="hljs-keyword">this</span>.pixelMap
        }
      }
    };

    <span class="hljs-comment">// 发布通知</span>
    notificationManager.publish(notificationRequest, (err) =&gt; {
      <span class="hljs-keyword">if</span> (err) {
        console.error(`zsf Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
        <span class="hljs-keyword">return</span>;
      }
      console.info(<span class="hljs-string">'zsf Succeeded in publishing notification.'</span>);
    });
  }
})

}

build() { Row() { Column() { Button(‘按钮’).fontColor(Color.White).fontSize(40) .onClick(this.onClickBtn.bind(this)) } .width(‘100%’) //®.alignItems(HorizontalAlign.Start) } .height(‘100%’) } }<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

module.json5里没指定requestPermissions



关于HarmonyOS 鸿蒙Next notificationManager.publish无效的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

4 回复
lz解决了这个问题吗

已经开启了还是发不出来通知 基本的纯文本也发不出来

HarmonyOS的分布式文件系统让我在多设备间传输文件变得轻松无比。

回到顶部