97色伦色在线综合视频,无玛专区,18videosex性欧美黑色,日韩黄色电影免费在线观看,国产精品伦理一区二区三区,在线视频欧美日韩,亚洲欧美在线中文字幕不卡

網(wǎng)絡(luò)營銷導(dǎo)向企業(yè)網(wǎng)站建設(shè)的原則站外調(diào)用WordPress評論

鶴壁市浩天電氣有限公司 2026/01/24 14:37:12
網(wǎng)絡(luò)營銷導(dǎo)向企業(yè)網(wǎng)站建設(shè)的原則,站外調(diào)用WordPress評論,江蘇省教育現(xiàn)代化建設(shè)水平監(jiān)測網(wǎng)站,焦作app網(wǎng)站建設(shè)今天開始咱們的系統(tǒng)服務(wù)調(diào)用系列分享。系統(tǒng)服務(wù)是鴻蒙應(yīng)用與底層系統(tǒng)交互的核心通道#xff0c;而通知服務(wù)#xff08;NotificationCenter#xff09;更是高頻剛需 —— 無論是消息推送、事件提醒還是功能跳轉(zhuǎn)#xff0c;都離不開它。這篇咱們聚焦 NotificationCenter 的核…今天開始咱們的系統(tǒng)服務(wù)調(diào)用系列分享。系統(tǒng)服務(wù)是鴻蒙應(yīng)用與底層系統(tǒng)交互的核心通道而通知服務(wù)NotificationCenter更是高頻剛需 —— 無論是消息推送、事件提醒還是功能跳轉(zhuǎn)都離不開它。這篇咱們聚焦 NotificationCenter 的核心用法從權(quán)限申請、通知創(chuàng)建到點擊跳轉(zhuǎn)結(jié)合實戰(zhàn)代碼一步步拆解為后續(xù)位置提醒 APP的開發(fā)打牢基礎(chǔ)一、通知服務(wù)核心認(rèn)知1. 通知的應(yīng)用場景鴻蒙的通知服務(wù)支持多種場景系統(tǒng)事件提醒如位置到達(dá)、任務(wù)到期應(yīng)用內(nèi)消息推送如好友消息、更新提示功能快捷入口如通知欄直接操作應(yīng)用功能重要信息展示如驗證碼、交易通知2. 核心 API 與權(quán)限要求核心模塊ohos.notificationNotificationCenter必備權(quán)限ohos.permission.NOTIFICATION_CONTROLLERAPI9關(guān)鍵能力創(chuàng)建通知、設(shè)置樣式、發(fā)送通知、監(jiān)聽點擊事件、取消通知二、通知開發(fā)三步走權(quán)限 - 創(chuàng)建 - 發(fā)送1. 權(quán)限申請合規(guī)第一步通知權(quán)限屬于普通權(quán)限但仍需在配置文件聲明并動態(tài)申請部分設(shè)備默認(rèn)關(guān)閉// module.json5 配置聲明 { module: { requestPermissions: [ { name: ohos.permission.NOTIFICATION_CONTROLLER, reason: 用于發(fā)送位置到達(dá)提醒通知, usedScene: { abilities: [MainAbility], when: always } } ] } }動態(tài)申請代碼結(jié)合權(quán)限管理模塊import abilityAccessCtrl from ohos.abilityAccessCtrl; import notification from ohos.notification; import common from ohos.app.ability.common; /** * 檢查并申請通知權(quán)限 */ export async function requestNotificationPermission(context: common.UIAbilityContext): Promiseboolean { const atManager abilityAccessCtrl.createAtManager(); try { // 檢查權(quán)限狀態(tài) const authResult await atManager.checkAccessToken( abilityAccessCtrl.createTokenID(), ohos.permission.NOTIFICATION_CONTROLLER ); if (authResult abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { console.log(通知權(quán)限已授予); return true; } // 動態(tài)申請權(quán)限 const reqResult await atManager.requestPermissionsFromUser(context, [ohos.permission.NOTIFICATION_CONTROLLER]); const granted reqResult.authResults[0] 0; console.log(通知權(quán)限申請結(jié)果${granted ? 成功 : 失敗}); return granted; } catch (err) { console.error(通知權(quán)限處理異常${JSON.stringify(err)}); return false; } }2. 創(chuàng)建通知實例自定義樣式鴻蒙支持多種通知樣式普通通知、長文本通知、圖片通知等咱們以位置提醒場景常用的普通通知為例包含標(biāo)題、內(nèi)容和跳轉(zhuǎn)入口import notification from ohos.notification; import wantAgent from ohos.wantAgent; import common from ohos.app.ability.common; /** * 創(chuàng)建位置提醒通知實例 * param context 上下文 * param title 通知標(biāo)題 * param content 通知內(nèi)容 * returns 通知實例 */ export async function createLocationReminderNotification( context: common.UIAbilityContext, title: string, content: string ): Promisenotification.Notification { // 1. 創(chuàng)建跳轉(zhuǎn)代理點擊通知跳轉(zhuǎn)應(yīng)用頁面 const wantAgentInfo { wants: [{ bundleName: context.applicationInfo.bundleName, abilityName: MainAbility, parameters: { from: notification, type: location_reminder } // 攜帶跳轉(zhuǎn)參數(shù) }], operationType: wantAgent.OperationType.START_ABILITY, requestCode: 1002 }; const jumpAgent await wantAgent.getWantAgent(wantAgentInfo); // 2. 構(gòu)建通知內(nèi)容 const notificationContent new notification.NotificationContent({ contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, normal: { title: title, text: content, additionalText: 點擊查看詳情 } }); // 3. 構(gòu)建通知請求 const notificationRequest { id: Date.now(), // 通知唯一ID用于后續(xù)取消 content: notificationContent, wantAgent: jumpAgent, // 綁定跳轉(zhuǎn)事件 priority: notification.Priority.HIGH, // 優(yōu)先級高優(yōu)先級會主動彈窗 showOnLockScreen: true, // 鎖屏顯示 isAutoCancel: true // 點擊后自動取消 }; return notificationRequest; }3. 發(fā)送與取消通知import notification from ohos.notification; // 全局存儲通知ID用于取消 let currentNotificationId: number -1; /** * 發(fā)送通知 */ export async function sendNotification(notificationRequest: notification.Notification): Promiseboolean { try { // 保存通知ID currentNotificationId notificationRequest.id; // 發(fā)送通知 await notification.publish(notificationRequest); console.log(通知發(fā)送成功ID${currentNotificationId}); return true; } catch (err) { console.error(通知發(fā)送失敗${JSON.stringify(err)}); return false; } } /** * 取消通知單個或全部 */ export async function cancelNotification(notificationId?: number) { try { if (notificationId) { await notification.cancel(notificationId); console.log(取消通知成功ID${notificationId}); } else { await notification.cancelAll(); console.log(取消所有通知成功); } } catch (err) { console.error(取消通知失敗${JSON.stringify(err)}); } }三、實戰(zhàn)通知點擊跳轉(zhuǎn)與參數(shù)接收1. 接收跳轉(zhuǎn)參數(shù)在目標(biāo) Ability 的onCreate或onNewWant中接收通知跳轉(zhuǎn)參數(shù)// MainAbility.ets onNewWant(want: Want) { // 接收通知跳轉(zhuǎn)參數(shù) const from want.parameters?.[from]; const type want.parameters?.[type]; if (from notification type location_reminder) { console.log(從位置提醒通知跳轉(zhuǎn)進(jìn)入); // 跳轉(zhuǎn)到位置詳情頁 this.context.startAbility({ url: pages/LocationDetailPage }); } }2. 完整調(diào)用流程UI 組件觸發(fā)Entry Component struct NotificationDemoPage { private context getContext(this) as common.UIAbilityContext; build() { Column({ space: 30 }) .width(100%) .height(100%) .padding(30) .backgroundColor(#f5f5f5) { Text(通知服務(wù)演示) .fontSize(32) .fontWeight(FontWeight.Bold) Button(申請通知權(quán)限) .type(ButtonType.Capsule) .width(250) .height(60) .backgroundColor(#2f54eb) .onClick(async () { const granted await requestNotificationPermission(this.context); Toast.show({ message: granted ? 權(quán)限申請成功 : 權(quán)限申請失敗 }); }) Button(發(fā)送位置提醒通知) .type(ButtonType.Capsule) .width(250) .height(60) .backgroundColor(#2f54eb) .onClick(async () { const notification await createLocationReminderNotification( this.context, 位置提醒, 您已到達(dá)目標(biāo)區(qū)域點擊查看詳情 ); const success await sendNotification(notification); Toast.show({ message: success ? 通知發(fā)送成功 : 通知發(fā)送失敗 }); }) Button(取消當(dāng)前通知) .type(ButtonType.Capsule) .width(250) .height(60) .backgroundColor(#ff4d4f) .onClick(() { cancelNotification(currentNotificationId); }) } } }四、實戰(zhàn)踩坑指南1. 通知不顯示的常見原因? 未申請權(quán)限務(wù)必先通過動態(tài)申請獲取NOTIFICATION_CONTROLLER權(quán)限? 通知 ID 重復(fù)每次發(fā)送建議使用唯一 ID如時間戳避免覆蓋已有通知? 應(yīng)用處于后臺凍結(jié)狀態(tài)需確保應(yīng)用有后臺運行權(quán)限后續(xù)系列會講2. 跳轉(zhuǎn)失敗的解決方案? 檢查want參數(shù)bundleName和abilityName必須與配置文件一致? 目標(biāo)頁面未注冊確保跳轉(zhuǎn)的 Ability 或 Page 已在main_pages.json中配置? 權(quán)限不足部分場景需申請ohos.permission.START_ABILITIES_FROM_BACKGROUND權(quán)限。加入班級學(xué)習(xí)鴻蒙開發(fā)
版權(quán)聲明: 本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請聯(lián)系我們進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

網(wǎng)站地圖制作怎么做28招商加盟網(wǎng)

網(wǎng)站地圖制作怎么做,28招商加盟網(wǎng),如何制作外貿(mào)網(wǎng)站,企業(yè)公司建站平臺大模型商業(yè)化新思路#xff1a;捆綁銷售GPU與Anything-LLM服務(wù) 在AI技術(shù)快速滲透企業(yè)運營的今天#xff0c;越來越

2026/01/23 00:34:02

3合一網(wǎng)站設(shè)計師培訓(xùn)多久

3合一網(wǎng)站,設(shè)計師培訓(xùn)多久,wordpress文件管理插件,天津室內(nèi)設(shè)計公司排行在前端開發(fā)中#xff0c;“內(nèi)存”似乎是個“隱形選手”——平時不顯山露水#xff0c;一旦出問題就可能讓頁面越用越卡、甚

2026/01/23 09:29:01

不記得在哪里做的網(wǎng)站備案wordpress 插件怎么用

不記得在哪里做的網(wǎng)站備案,wordpress 插件怎么用,網(wǎng)聯(lián)科技網(wǎng)站建設(shè),桂林做網(wǎng)站Atlas數(shù)據(jù)庫模式管理深度解析#xff1a;2025年企業(yè)級應(yīng)用實戰(zhàn)指南 【免費下載鏈接】atlas A mod

2026/01/23 01:50:01

做商業(yè)網(wǎng)站沒有注冊公司怎么建設(shè)電影網(wǎng)站

做商業(yè)網(wǎng)站沒有注冊公司,怎么建設(shè)電影網(wǎng)站,開發(fā)網(wǎng)站開發(fā)工程師招聘要求,什么公司需要做網(wǎng)站灰度發(fā)布流程設(shè)計#xff1a;新版本逐步上線降低風(fēng)險 在語音識別系統(tǒng)日益深入企業(yè)辦公、會議記錄和智能客服的今天#

2026/01/23 16:50:01