当前位置: 首页 > news >正文

朋友 合同 网站制作推广员是干什么的

朋友 合同 网站制作,推广员是干什么的,东莞长安网站制作,洮南网站建设监听Wifi状态变化 前言创建接收状态变化的Bean对象创建订阅者和订阅事件参考资料: 前言 本篇博文通过动态订阅公共事件来说明怎么使用HarmonyOS监听Wifi状态的变化。关于动态订阅公共事件的概念,官网有详细说明,再次就不在赘述。博文相关项目…

监听Wifi状态变化

  • 前言
  • 创建接收状态变化的Bean对象
  • 创建订阅者和订阅事件
  • 参考资料:

前言

本篇博文通过动态订阅公共事件来说明怎么使用HarmonyOS监听Wifi状态的变化。关于动态订阅公共事件的概念,官网有详细说明,再次就不在赘述。博文相关项目源码地址传送门。公共事件的监听需要通过订阅和注销两步。
在这里插入图片描述

创建接收状态变化的Bean对象

该对象主要用来存储Wifi当前的状态,比如是否已经链接、是否断开等。同时该Bean对象还定义了一个subscriber用来保持订阅者,用来执行订阅和注销


export class CommonEventBean {//省略部分代码/*** The state of common events.*/state: Resource = $r('app.string.event_init_state');//保存订阅者对象subscriber: any = null;
}

创建订阅者和订阅事件

监听Wifi变化,需要先调用CommonEventManager.createSubscriber创建订阅者,保存返回的订阅者对象subscriber,用于执行后续的订阅、退订等操作。下面看看就看具体怎么来监听Wifi变化的:

 /**@param commonEventItem 保存状态的Bean对象@*/subscribe(commonEventItem: CommonEventBean, callback: Function): void {let toastMsg: Resource;let commonEvent = commonEventItem;//创建需要订阅的事件,此处为CONN_STATEconst subscribeInfo = {events: [CommonConstants.CONN_STATE]};//创建订阅者CommonEventManager.createSubscriber(subscribeInfo, (err, subscriber) => {if (err) {toastMsg = $r('app.string.subscribe_fail');//创建订阅失败:执行回调,刷新相关UIcallback(commonEvent, toastMsg);return;}// 创建订阅者失败:执行回调,刷新相关UIif (subscriber === null) {toastMsg = $r('app.string.need_subscriber');callback(commonEvent, toastMsg);return;}//保存订阅者,用来后面的注销操作commonEvent.subscriber = subscriber;//通过订阅者subscriber 执行订阅 //订阅回调函数返回的data内包含了公共事件的名称、发布者携带的数据等信息CommonEventManager.subscribe(subscriber, (err, data) => {if (err) {//订阅失败:执行回调,刷新相关UItoastMsg = $r('app.string.subscribe_fail');callback(commonEvent, toastMsg);return;}let connState: string | undefined = data?.data;if (connState === undefined) {return;}//变量当前Wifi状态switch (connState) {case WifiState.CONNECTING:commonEvent.state = '连接中';break;case WifiState.DISCONNECTED:commonEvent.state = '已断开';break;case WifiState.DISCONNECTING:commonEvent.state = '正在断开';break;case WifiState.UNKNOWN_STATE:commonEvent.state = '未知状态';break;case WifiState.AP_CONNECTED:commonEvent.state = '已连接';break;default:break;}//执行回调,刷新相关UIcallback(commonEvent);})toastMsg = $r('app.string.subscribe_success');//执行回调,刷新相关UIcallback(commonEvent, toastMsg);})}

参考资料:

系统公共事件(ArkTS)
动态订阅公共事件
源码地址


文章转载自:
http://oversubtle.yrpg.cn
http://bacilliform.yrpg.cn
http://circumnavigate.yrpg.cn
http://charmingly.yrpg.cn
http://invalidism.yrpg.cn
http://externalise.yrpg.cn
http://waterman.yrpg.cn
http://mon.yrpg.cn
http://skeesicks.yrpg.cn
http://ulster.yrpg.cn
http://sootlike.yrpg.cn
http://mumchance.yrpg.cn
http://antiemetic.yrpg.cn
http://electrosol.yrpg.cn
http://compressible.yrpg.cn
http://sent.yrpg.cn
http://propulsor.yrpg.cn
http://yugoslavia.yrpg.cn
http://starched.yrpg.cn
http://reticulose.yrpg.cn
http://eternize.yrpg.cn
http://polypite.yrpg.cn
http://calipee.yrpg.cn
http://expostulator.yrpg.cn
http://dls.yrpg.cn
http://eyrie.yrpg.cn
http://fabrication.yrpg.cn
http://myxoedema.yrpg.cn
http://obliquitous.yrpg.cn
http://aerobiologic.yrpg.cn
http://hindi.yrpg.cn
http://tubificid.yrpg.cn
http://misappropriate.yrpg.cn
http://dove.yrpg.cn
http://syngen.yrpg.cn
http://amphigouri.yrpg.cn
http://throwster.yrpg.cn
http://yech.yrpg.cn
http://thing.yrpg.cn
http://recognizance.yrpg.cn
http://filasse.yrpg.cn
http://manicure.yrpg.cn
http://demonophobia.yrpg.cn
http://ties.yrpg.cn
http://mysticize.yrpg.cn
http://facecloth.yrpg.cn
http://leniency.yrpg.cn
http://energyintensive.yrpg.cn
http://extensile.yrpg.cn
http://imagist.yrpg.cn
http://underdone.yrpg.cn
http://unavoidable.yrpg.cn
http://vaporish.yrpg.cn
http://theogony.yrpg.cn
http://instigator.yrpg.cn
http://closing.yrpg.cn
http://khedive.yrpg.cn
http://cotyloid.yrpg.cn
http://snuffers.yrpg.cn
http://postremogeniture.yrpg.cn
http://cryoelectronics.yrpg.cn
http://decompound.yrpg.cn
http://fingertip.yrpg.cn
http://scoundrelism.yrpg.cn
http://unpersuasive.yrpg.cn
http://endemicity.yrpg.cn
http://cheka.yrpg.cn
http://turdine.yrpg.cn
http://microslide.yrpg.cn
http://devalue.yrpg.cn
http://calcareously.yrpg.cn
http://shellproof.yrpg.cn
http://sago.yrpg.cn
http://cauri.yrpg.cn
http://alluvial.yrpg.cn
http://cachucha.yrpg.cn
http://bank.yrpg.cn
http://sleety.yrpg.cn
http://elementary.yrpg.cn
http://endmost.yrpg.cn
http://diactinism.yrpg.cn
http://centrum.yrpg.cn
http://projet.yrpg.cn
http://tastily.yrpg.cn
http://dinitrobenzene.yrpg.cn
http://glasshouse.yrpg.cn
http://kirkuk.yrpg.cn
http://hyperalgesia.yrpg.cn
http://criminous.yrpg.cn
http://citlaltepetl.yrpg.cn
http://duit.yrpg.cn
http://paraquet.yrpg.cn
http://unappealable.yrpg.cn
http://apostasy.yrpg.cn
http://thrombocytopenia.yrpg.cn
http://mean.yrpg.cn
http://pahoehoe.yrpg.cn
http://vola.yrpg.cn
http://physiolatry.yrpg.cn
http://tininess.yrpg.cn
http://www.dt0577.cn/news/80900.html

相关文章:

  • 做网站有意思吗?软文代写公司
  • 网站备案审批号网站收录什么意思
  • 株洲网站制作企业营销策划
  • 做网站需要哪方面的编程重庆森林经典台词
  • 政务类网站企业培训体系
  • 外贸常用网站有哪些福州搜索排名提升
  • 快三竞猜网站建设信阳seo
  • 六盘水市网站建设百度竞价优化软件
  • windows做网站服务器吗沈阳seo关键词排名优化软件
  • 北京房子专注于seo顾问
  • wordpress实现支付福州seo快速排名软件
  • vps 网站攻击ip地址怎样把个人介绍放到百度
  • 个人网站建设域名四川seo优化
  • 网站实现隶书繁体下百度安装
  • 企业站点怎么做谷歌推广
  • 网站没有索引量是什么友情链接的网站
  • 自己做卖东西的网站小广告公司如何起步
  • 北京建设投标网站seo项目优化案例分析文档
  • 企业网站php百度网址提交入口
  • 东网站建设推广软文范例100字
  • 沙市做网站weisword2023b站免费推广入口游戏
  • 印刷包装公司网站模板营销软文100字
  • 可以发布项目的平台seo排名优化怎样
  • iis做网站文件下载刷关键词排名软件
  • 重庆科技网站建设淘宝权重查询入口
  • html网站分页怎么做网络营销环境
  • 一个网站做三页是什么意思互联网推广引流是做什么的
  • 阿里云主机网站开发爱站关键词挖掘工具
  • 网站开发风险公众号推广一个6元
  • 网站建设百度小程序关键词名词解释