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

怎样建设自己的商业网站建设管理网站首页

怎样建设自己的商业网站,建设管理网站首页,县区工会网站建设方案,山东华建建设有限公司网站介绍 本篇Codelab使用ArkTS语言实现计步器应用#xff0c;应用主要包括计步传感器、定位服务和后台任务功能#xff1a; 通过订阅计步器传感器获取计步器数据#xff0c;处理后显示。通过订阅位置服务获取位置数据#xff0c;处理后显示。通过服务开发实现后台任务功能。…介绍 本篇Codelab使用ArkTS语言实现计步器应用应用主要包括计步传感器、定位服务和后台任务功能 通过订阅计步器传感器获取计步器数据处理后显示。通过订阅位置服务获取位置数据处理后显示。通过服务开发实现后台任务功能。 相关概念 计步传感器订阅计步器传感器数据系统返回相关数据。后台任务管理应用中存在用户能够直观感受到的且需要一直在后台运行的业务时如后台播放音乐可以使用长时任务机制。位置服务位置服务提供GNSS定位、网络定位、地理编码、逆地理编码、国家码和地理围栏等基本功能。 相关权限 本篇Codelab用到了计步传感器、后台任务及位置服务功能需要在配置文件module.json5里添加权限 ● ohos.permission.ACTIVITY_MOTION ● ohos.permission.KEEP_BACKGROUND_RUNNING ● ohos.permission.APPROXIMATELY_LOCATION ● ohos.permission.LOCATION ● ohos.permission.LOCATION_IN_BACKGROUND 环境搭建 安装DevEco Studio详情请参考 下载和安装软件。 设置DevEco Studio开发环境DevEco Studio开发环境需要依赖于网络环境需要连接上网络才能确保工具的正常使用可以根据如下两种情况来配置开发环境如果可以直接访问Internet只需进行 下载HarmonyOS SDK 操作。 如果网络不能直接访问Internet需要通过代理服务器才可以访问请参考 配置开发环境 。 开发者可以参考以下链接完成设备调试的相关配置 使用真机进行调试 使用模拟器进行调试 代码结构解读 本篇Codelab只对核心代码进行讲解对于完整代码我们会在源码下载或gitee中提供。 ├──entry/src/main/ets // 代码区 │ ├──common │ │ ├──constants │ │ │ └──CommonConstants.ets // 公共常量 │ │ └──utils // 日志类 │ │ ├──BackgroundUtil.ets // 后台任务工具类 │ │ ├──GlobalContext.ets // 首选项工具类 │ │ ├──LocationUtil.ets // 位置服务工具类 │ │ ├──Logger.ets // 日志工具类 │ │ ├──NumberUtil.ets // 数字处理工具类 │ │ └──StepsUtil.ets // 计步器工具类 │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 │ ├──pages │ │ └──HomePage.ets // 应用首页 │ └──view │ ├──CompletionStatus.ets // 目标设置页 │ ├──CurrentSituation.ets // 计步信息页 │ └──InputDialog.ets // 自定义弹窗 └──entry/src/main/resources // 资源文件夹构建应用界面 计步器页面主要由Stack堆叠容器组件、Component自定义组件和CustomDialog自定义弹窗组件完成页面布局效果如图所示 // HomePage.ets build(){ Stack({ alignContent: Alignment.TopStart }){ CompletionStatus({progressValue:$progressValue })CurrentSituation({currentSteps:this.currentSteps,startPosition:this.startPosition,currentLocation:this.currentLocation })Row(){ Button(this.isStart ?$r(app.string.stop):$r(app.string.start)) ... } ... } ... }计步传感器 应用启动后申请计步传感器权限获取权限后订阅计步器传感器。通过订阅获取到计步传感器数据解析处理后在页面显示。效果如图所示 // HomePage.ets requestPermissions():void{let atManager abilityAccessCtrl.createAtManager(); try{atManager.requestPermissionsFromUser(this.context, CommonConstants.REQUEST_PERMISSIONS).then((data){ if(data.authResults[0]!0|| data.authResults[1]!0){ return; } const that this; try{sensor.on(sensor.SensorId.PEDOMETER,(data){ try{ if(that.isStart){ if(StepsUtil.checkStrIsEmpty(that.oldSteps)){that.oldSteps data.steps.toString();StepsUtil.putStorageValue(CommonConstants.OLD_STEPS, that.oldSteps); }else{that.currentSteps (data.steps - NumberUtil._parseInt(that.oldSteps,10)).toString(); } }else{that.currentSteps data.steps.toString(); }if(StepsUtil.checkStrIsEmpty(that.stepGoal)||!that.isStart){ return; }StepsUtil.putStorageValue(CommonConstants.CURRENT_STEPS, that.currentSteps);that.progressValue StepsUtil.getProgressValue(NumberUtil._parseInt(that.stepGoal,10),NumberUtil._parseInt(that.currentSteps,10));StepsUtil.putStorageValue(CommonConstants.PROGRESS_VALUE_TAG,String(that.progressValue)); }catch(err){Logger.error(TAG,Sensor on err JSON.stringify(err)); } },{ interval: CommonConstants.SENSOR_INTERVAL }); ... }位置服务 应用启动后申请位置服务权限获取权限后启动服务启动服务后订阅位置服务。通过订阅获取到位置服务数据解析处理后在页面显示。效果如图所示 // HomePage.ets requestPermissions():void{ ...LocationUtil.geolocationOn((location: geoLocationManager.Location){ if(this.latitude location.latitude this.longitude location.longitude){ return; } this.latitude location.latitude; this.longitude location.longitude;let reverseGeocodeRequest: geoLocationManager.ReverseGeoCodeRequest { latitude:this.latitude, longitude:this.longitude };geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then(data { if(data[0].placeName){ this.currentLocation data[0].placeName; } }).catch((err: Error){Logger.error(TAG,GetAddressesFromLocation err JSON.stringify(err)); }); }); ... }将位置服务相关的函数封装到工具类中。 // LocationUtil.ets classLocationUtil{ geolocationOn(locationChange:(location: geoLocationManager.Location)void):void{let requestInfo: geoLocationManager.LocationRequest { priority:0x203, scenario:0x300, timeInterval:0, distanceInterval:0, maxAccuracy:0 } try{geoLocationManager.on(locationChange, requestInfo, locationChange); }catch(err){console.error(locationChange error: JSON.stringify(err)); } }geolocationOff():void{geoLocationManager.off(locationChange); } }后台任务 点击开始按钮开启后台任务通过后台任务管理方法配置申请的后台模式等参数启动后台任务。 // HomePage.ets build(){ Stack({ alignContent: Alignment.TopStart }){ ... Row(){ Button(this.isStart ?$r(app.string.stop):$r(app.string.start)) ... .onClick((){ if(this.isStart){ ...BackgroundUtil.stopContinuousTask(this.context); }else{ if(this.stepGoal ||this.currentLocation ){promptAction.showToast({ message: CommonConstants.WAIT }); }else{ ...BackgroundUtil.startContinuousTask(this.context); } }StepsUtil.putStorageValue(CommonConstants.IS_START,String(this.isStart)); }) } ... }// BackgroundUtil.ets export classBackgroundUtil{ publicstaticstartContinuousTask(context: common.UIAbilityContext):void{let wantAgentInfo: wantAgent.WantAgentInfo {wants:[ {bundleName: context.abilityInfo.bundleName,abilityName: context.abilityInfo.name } ],operationType: wantAgent.OperationType.START_ABILITY,requestCode:0,wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] };wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj){ try{backgroundTaskManager.startBackgroundRunning(context,backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then((){Logger.info(TAG,startBackgroundRunning succeeded); }).catch((err: Error){Logger.error(TAG, startBackgroundRunning failed Cause:${JSON.stringify(err)}); }); }catch(error){Logger.error(TAG, stopBackgroundRunning failed. error:${JSON.stringify(error)} ); } }); }publicstaticstopContinuousTask(context: common.UIAbilityContext):void{ try{backgroundTaskManager.stopBackgroundRunning(context).then((){Logger.info(TAG,stopBackgroundRunning succeeded); }).catch((err: Error){Logger.error(TAG, stopBackgroundRunning failed Cause:${JSON.stringify(err)}); }); }catch(error){Logger.error(TAG, stopBackgroundRunning failed. error:${JSON.stringify(error)} ); } } }总结 您已经完成了本次Codelab的学习并了解到以下知识点 计步器传感器的功能实现。位置服务的功能实现。后台任务的功能实现。 为了能让大家更好的学习鸿蒙 (Harmony OS) 开发技术这边特意整理了《鸿蒙 (Harmony OS)开发学习手册》共计890页希望对大家有所帮助https://qr21.cn/FV7h05 《鸿蒙 (Harmony OS)开发学习手册》 入门必看https://qr21.cn/FV7h05 应用开发导读(ArkTS)应用开发导读(Java) HarmonyOS 概念https://qr21.cn/FV7h05 系统定义技术架构技术特性系统安全 如何快速入门https://qr21.cn/FV7h05 基本概念构建第一个ArkTS应用构建第一个JS应用…… 开发基础知识https://qr21.cn/FV7h05 应用基础知识配置文件应用数据管理应用安全管理应用隐私保护三方应用调用管控机制资源分类与访问学习ArkTS语言…… 基于ArkTS 开发https://qr21.cn/FV7h05 Ability开发UI开发公共事件与通知窗口管理媒体安全网络与链接电话服务数据管理后台任务(Background Task)管理设备管理设备使用信息统计DFX国际化开发折叠屏系列……
http://www.huolong8.cn/news/345027/

相关文章:

  • 做外贸网站需要什么wordpress添加媒体无反应
  • 电脑建设银行怎样设置网站查询密码中山古镇做网站的公司
  • 武隆网站建设哪家好企业网站方案设计
  • 聚牛建设网站网站添加可信任站点怎么做
  • 福州高端网站定制关键词排名优化网站建设公司哪家好
  • 网站所有页面成都市网站建
  • 环球资源网商务网站建设目的河北seo
  • 淘宝客网站需要多大空间汝阳县建设局网站
  • 沧州市网站制作公司青海西宁做网站多少钱
  • 互联网客户做网站北京随喜设计网站
  • 遵义网站建设公司价格wordpress清空缓存
  • 大连城乡建设局网站网站开发报价说明
  • 优化排名推广教程网站网站窗口代码
  • 网站规划与建设策划书好一点的网站是怎么做的
  • 惠州做网站电话50个办厂好项目
  • 外贸长尾关键词挖掘网站网站安全认证多少钱
  • 网站优化有哪些技巧网站开发建设方案的主要内容包括
  • 网站优化公司推荐网站样版风格排版
  • 网站进入沙盒后婚纱网站建设 最开始
  • 龙华企业网站建设浙江怎么制作网站
  • 绍兴外贸网站建设wordpress动漫网站
  • 怎样把网站做成app自己制作网站的方法是
  • 湛江专业做网站外贸网站seo推广
  • 网站建设成都哪家公司好黄金多少钱一克
  • 网站建设图片大全网站建设是指
  • 网站交互是什么深圳跨境电商公司排行榜
  • 怎样只做自己的网站做个企业网网站怎么做
  • 网站的规划与建设_按时间顺序可以分为哪等五个阶段wordpress加载更多文章
  • 擅自使用他人产品做网站宣传织梦程序如何搭建网站
  • 建站公司专业定制网络服务器配置