辽宁省交通建设投资集团网站wordpress导入sql

张小明 2026/1/7 11:16:26
辽宁省交通建设投资集团网站,wordpress导入sql,梧州论坛热门主题,apache 本地网站前两篇咱们分别搞定了通知服务#xff08;发送提醒#xff09;和地理位置服务#xff08;获取位置#xff09;#xff0c;这篇咱们先学习设备信息#xff08;deviceInfo#xff09;的核心用法#xff0c;适配不同设备的硬件和系统特性#xff0c;再将三大服务整合发送提醒和地理位置服务获取位置这篇咱们先学习设备信息deviceInfo的核心用法适配不同设备的硬件和系统特性再将三大服务整合完成 “位置提醒 APP” 的完整开发。让咱们从设备适配到功能闭环一步步实现可直接复用的实战项目一、设备信息服务核心认知1. 设备信息的应用价值设备适配根据屏幕尺寸调整 UI 布局、根据系统版本适配 API功能优化根据设备型号调整定位策略如高端机支持高精度 GNSS问题排查记录设备信息用于日志分析快速定位兼容性问题个性化服务根据设备特性提供定制化功能如平板端显示更多操作入口。2. 核心 API 与可获取信息核心模块ohos.deviceInfo设备信息、ohos.screen屏幕信息关键信息设备基础信息型号、厂商、设备 ID系统信息系统版本、API 版本、设备类型屏幕信息屏幕尺寸、分辨率、像素密度。二、设备信息获取实战1. 获取设备基础信息import deviceInfo from ohos.deviceInfo; /** * 获取设备基础信息 */ export function getDeviceBaseInfo(): { deviceModel: string; // 设备型号 manufacturer: string; // 设备厂商 osVersion: string; // 系统版本 apiVersion: number; // API版本 deviceType: string; // 设备类型phone/tablet/watch等 } { return { deviceModel: deviceInfo.deviceModel, // 如Mate 60 Pro manufacturer: deviceInfo.manufacturer, // 如Huawei osVersion: deviceInfo.osVersion, // 如4.0.0.188 apiVersion: deviceInfo.apiVersion, // 如10 deviceType: deviceInfo.deviceType // 如phone }; }2. 获取屏幕信息适配 UI 布局import screen from ohos.screen; /** * 获取屏幕信息 */ export function getScreenInfo(): { screenWidth: number; // 屏幕宽度像素 screenHeight: number; // 屏幕高度像素 density: number; // 像素密度 dpi: number; // 屏幕DPI } { const mainScreen screen.getDefaultScreen(); const screenRect mainScreen.getRect(); const density mainScreen.getDensity(); const dpi mainScreen.getDpi(); return { screenWidth: screenRect.width, screenHeight: screenRect.height, density: density, dpi: dpi }; }3. 设备适配实战根据设备类型调整功能/** * 根据设备类型调整定位配置 * 手机高精度模式平板平衡模式手表低功耗模式 */ export function getLocationConfigByDeviceType(): geoLocationManager.LocationRequest { const deviceInfo getDeviceBaseInfo(); let priority: geoLocationManager.LocationRequestPriority; switch (deviceInfo.deviceType) { case phone: priority geoLocationManager.LocationRequestPriority.HIGH_ACCURACY; break; case tablet: priority geoLocationManager.LocationRequestPriority.BALANCED; break; case watch: priority geoLocationManager.LocationRequestPriority.LOW_POWER; break; default: priority geoLocationManager.LocationRequestPriority.BALANCED; } return { priority: priority, interval: deviceInfo.deviceType watch ? 10000 : 5000, // 手表定位间隔 longer distance: 10, scenario: geoLocationManager.LocationScenario.NAVIGATION }; }三、整合三大服务位置提醒 APP 完整实现1. 项目核心流程应用启动获取设备信息适配 UI 布局和定位策略权限申请批量申请通知权限和定位权限设置目标用户输入或选择目标位置经纬度定位监听启动持续定位实时计算与目标位置的距离提醒触发到达目标区域发送通知并停止定位点击跳转用户点击通知进入应用查看详情。2. 完整代码实现1全局工具类整合utils/SystemServiceUtil.ets// 整合前两篇的通知、定位工具方法加上设备信息方法 import abilityAccessCtrl from ohos.abilityAccessCtrl; import notification from ohos.notification; import wantAgent from ohos.wantAgent; import geoLocationManager from ohos.geolocation; import deviceInfo from ohos.deviceInfo; import screen from ohos.screen; import common from ohos.app.ability.common; // 权限申请批量申请通知和定位权限 export async function requestAllPermissions(context: common.UIAbilityContext): Promiseboolean { const permissions [ ohos.permission.NOTIFICATION_CONTROLLER, ohos.permission.APPROXIMATELY_LOCATION, ohos.permission.LOCATION ]; const atManager abilityAccessCtrl.createAtManager(); try { const authResults await atManager.checkAccessToken( abilityAccessCtrl.createTokenID(), permissions ); const needReqPerms permissions.filter( (perm, index) authResults[index] ! abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED ); if (needReqPerms.length 0) return true; const reqResult await atManager.requestPermissionsFromUser(context, needReqPerms); return reqResult.authResults.every(status status 0); } catch (err) { console.error(批量权限申请失败${JSON.stringify(err)}); return false; } } // 设备信息方法同上篇 export function getDeviceBaseInfo() { /* 省略复用前文代码 */ } export function getScreenInfo() { /* 省略复用前文代码 */ } export function getLocationConfigByDeviceType() { /* 省略复用前文代码 */ } // 通知方法同上篇 export async function createLocationReminderNotification() { /* 省略复用前文代码 */ } export async function sendNotification() { /* 省略复用前文代码 */ } // 定位方法同上篇 export function startContinuousLocation() { /* 省略复用前文代码 */ } export function stopContinuousLocation() { /* 省略复用前文代码 */ } export function isReachTargetArea() { /* 省略复用前文代码 */ }2主页面实现pages/LocationReminderPage.etsimport common from ohos.app.ability.common; import { requestAllPermissions, getDeviceBaseInfo, getScreenInfo, getLocationConfigByDeviceType, createLocationReminderNotification, sendNotification, startContinuousLocation, stopContinuousLocation, isReachTargetArea } from ../utils/SystemServiceUtil; Entry Component struct LocationReminderPage { private context getContext(this) as common.UIAbilityContext; State deviceInfoStr: string ; State currentLocation: string 未获取位置; State targetLat: string 39.9042; // 目标纬度默认值 State targetLng: string 116.4074; // 目标经度默认值 State reminderRadius: number 100; // 提醒半径米 State isTracking: boolean false; // 页面加载时获取设备信息 aboutToAppear() { this.loadDeviceInfo(); } // 加载设备信息 loadDeviceInfo() { const deviceInfo getDeviceBaseInfo(); const screenInfo getScreenInfo(); this.deviceInfoStr 设备${deviceInfo.manufacturer} ${deviceInfo.deviceModel} | 系统${deviceInfo.osVersion} | 屏幕${screenInfo.screenWidth}x${screenInfo.screenHeight}; } // 启动位置提醒 async startReminder() { // 1. 检查权限 const allGranted await requestAllPermissions(this.context); if (!allGranted) { Toast.show({ message: 部分权限未授予无法启动提醒 }); return; } // 2. 验证目标位置 const targetLoc { latitude: parseFloat(this.targetLat), longitude: parseFloat(this.targetLng) }; if (isNaN(targetLoc.latitude) || isNaN(targetLoc.longitude)) { Toast.show({ message: 目标位置格式错误 }); return; } // 3. 启动持续定位根据设备类型适配配置 this.isTracking true; Toast.show({ message: 位置提醒已启动正在跟踪您的位置 }); startContinuousLocation((currentLoc) { this.currentLocation 当前纬度${currentLoc.latitude.toFixed(6)}经度${currentLoc.longitude.toFixed(6)}; // 4. 判断是否到达目标区域 if (isReachTargetArea(currentLoc, targetLoc, this.reminderRadius)) { this.sendReminderNotification(); this.stopReminder(); } }, getLocationConfigByDeviceType()); } // 发送提醒通知 async sendReminderNotification() { const notification await createLocationReminderNotification( this.context, 位置提醒, 您已到达目标区域半径${this.reminderRadius}米点击查看详情 ); await sendNotification(notification); } // 停止位置提醒 stopReminder() { stopContinuousLocation(); this.isTracking false; Toast.show({ message: 位置提醒已停止 }); } build() { Column({ space: 25 }) .width(100%) .height(100%) .padding(30) .backgroundColor(#f5f5f5) { // 标题区域 Text(位置提醒APP) .fontSize(36) .fontWeight(FontWeight.Bold) .textAlign(TextAlign.Center) .width(100%) // 设备信息区域 Text(this.deviceInfoStr) .fontSize(16) .color(#666) .textAlign(TextAlign.Center) .width(100%) .lineHeight(24) // 目标位置输入区域 Column({ space: 15 }) .width(100%) .padding(20) .backgroundColor(#ffffff) .borderRadius(12) { Text(目标位置设置) .fontSize(20) .fontWeight(FontWeight.Medium) Row({ space: 10 }) .width(100%) { Text(纬度) .fontSize(18) .width(20%) TextInput({ text: this.targetLat }) .width(80%) .height(45) .padding(10) .border({ width: 1, color: #eee }) .borderRadius(8) .fontSize(18) .onChange((value) this.targetLat value) } Row({ space: 10 }) .width(100%) { Text(经度) .fontSize(18) .width(20%) TextInput({ text: this.targetLng }) .width(80%) .height(45) .padding(10) .border({ width: 1, color: #eee }) .borderRadius(8) .fontSize(18) .onChange((value) this.targetLng value) } Row({ space: 10 }) .width(100%) { Text(提醒半径) .fontSize(18) .width(30%) TextInput({ text: this.reminderRadius.toString() }) .width(70%) .height(45) .padding(10) .border({ width: 1, color: #eee }) .borderRadius(8) .fontSize(18) .onChange((value) this.reminderRadius parseInt(value) || 100) Text(米) .fontSize(18) .marginLeft(10) } } // 当前位置显示 Text(this.currentLocation) .fontSize(18) .width(100%) .textAlign(TextAlign.Center) .padding(15) .backgroundColor(#ffffff) .borderRadius(12) // 操作按钮区域 Row({ space: 30 }) .width(100%) .justifyContent(FlexAlign.Center) { Button(this.isTracking ? 停止提醒 : 启动提醒) .type(ButtonType.Capsule) .width(200) .height(60) .fontSize(20) .backgroundColor(this.isTracking ? #ff4d4f : #2f54eb) .onClick(() { if (this.isTracking) { this.stopReminder(); } else { this.startReminder(); } }) } } } }3配置文件完善module.json5{ module: { package: com.example.locationreminder, name: LocationReminder, mainAbility: MainAbility, requestPermissions: [ { name: ohos.permission.NOTIFICATION_CONTROLLER, reason: 用于发送位置到达提醒通知, usedScene: { abilities: [MainAbility], when: always } }, { name: ohos.permission.APPROXIMATELY_LOCATION, reason: 用于获取大致位置提供位置提醒服务, usedScene: { abilities: [MainAbility], when: inuse } }, { name: ohos.permission.LOCATION, reason: 用于获取精准位置提升提醒准确性, usedScene: { abilities: [MainAbility], when: inuse } } ], abilities: [ { name: .MainAbility, type: page, visible: true, skills: [ { entities: [entity.system.home], actions: [action.system.home] } ] } ] } }四、APP 核心功能说明1. 设备适配能力自动识别设备类型手机 / 平板 / 手表调整定位策略根据屏幕尺寸自适应 UI 布局在不同设备上显示正常适配不同 API 版本避免因系统版本差异导致功能异常。2. 合规性保障批量申请权限明确告知用户权限用途定位和通知功能可手动启停用户可控到达目标后自动停止定位降低功耗符合系统规范。3. 用户体验优化实时显示当前位置和设备信息状态透明支持自定义目标位置和提醒半径灵活适配不同场景通知点击跳转应用形成功能闭环。加入班级学习鸿蒙开发
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

网站建设需求分析报告功能怎么开网店具体流程

Go并发编程:原子操作与Context的深入解析(上) 在Go语言的并发编程中,同步是一个至关重要的话题。为了确保在多线程环境下数据的一致性和正确性,Go提供了丰富的工具和方法。本文将深入探讨Go标准库中用于同步的工具,包括原子操作和 context 包的使用。 原子操作 Go的…

张小明 2026/1/7 3:35:11 网站建设

怎么将网站关键词排名首页企业网站禁忌

PDFMiner 文本提取完全指南:从零基础到高级应用 【免费下载链接】pdfminer Python PDF Parser (Not actively maintained). Check out pdfminer.six. 项目地址: https://gitcode.com/gh_mirrors/pd/pdfminer 项目核心功能介绍 PDFMiner 是一款专业的 Python…

张小明 2026/1/7 3:35:13 网站建设

怎么学做网站PHPwordpress禁止响应

npm 和 npxnpm npdejs 的包仓库包管理器,他的痛点是 全局安装包会产生版本冲突,需要手动配置path 来执行相关命令,临时工具使用不便npx nodejs 的包执行器 无需安装,直接运行,内置与 npm 中,npx 会智能执行…

张小明 2026/1/7 3:35:14 网站建设

知名网站制作案例郑州市建筑企业服务中心官网

第一章:VSCode敏感文件编辑在开发过程中,VSCode常被用于编辑配置文件、密钥文件或包含敏感信息的脚本。不当操作可能导致凭据泄露或系统安全风险。因此,合理配置编辑环境与权限控制至关重要。启用工作区信任机制 VSCode内置“工作区信任”功能…

张小明 2026/1/7 3:35:17 网站建设

广州网站二级等保政务门户网站建设思想

第一章:Open-AutoGLM是在手机上操作还是云手机Open-AutoGLM 是一个面向自动化大语言模型任务执行的开源框架,其运行环境既支持实体移动设备,也兼容云手机平台。选择在哪种环境中部署,主要取决于性能需求、成本控制与使用场景。本地…

张小明 2026/1/7 3:35:16 网站建设

做网站用什么软件做南京营销

Draw.io Mermaid插件终极指南:从零开始掌握文本转图表神器 【免费下载链接】drawio_mermaid_plugin Mermaid plugin for drawio desktop 项目地址: https://gitcode.com/gh_mirrors/dr/drawio_mermaid_plugin 想要用简单的文本描述快速生成专业图表吗&#x…

张小明 2026/1/7 3:35:15 网站建设