




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
RAPI 类表 2 列出的 RAPI 类方法对开发移动应用程序最有帮助。表 2:对开发移动应用程序有用的 RAPI 类方法。方法说明Connect建立与设备的同步连接。CopyFileFromDevice将设备中的文件复制到 PC。CopyFileOnDevice将设备某个位置的文件复制到设备的另一新位置。CopyFileToDevice将 PC 中的文件复制到设备。CreateDeviceDirectory在设备中创建目录。CreateProcess启动设备中的应用程序。DeleteDeviceFile删除设备中的文件。DeviceFileExists检查设备中是否存在文件。Disconnect中断与设备的连接。EnumFiles提供与 FileName 参数提供的条件相匹配的 FileInformation 类数组列表。GetDeviceCapabilities检索设备的特定设备信息。GetDeviceFileAttributes检索特定设备文件的属性。GetDeviceFileSize检索设备文件的大小,以字节为单位。GetDeviceFileTime检索设备文件的日期时间。GetDeviceMemoryStatus检索设备的内存使用信息。GetDeviceSystemFolderPath检索到设备系统文件夹的路径。GetDeviceSystemInfo检索设备的系统详细信息。GetDeviceSystemPowerStatus检索设备的电源状态。GetDeviceVersion检索设备的操作系统版本。MoveDeviceFile将现有设备文件移到或重命名到一个新位置。RemoveDeviceDirectory删除设备中的目录。SetDeviceFileAttributes设置设备中文件的属性。SetDeviceFileTime设置设备中文件的日期时间。使用 RAPI 类为了简化 RAPI 类的使用过程,C# 代码示例中添加了 using 语句,VB.NET 代码示例中添加了 Imports 语句,如下所示:VC#.NETusing OpenNETCF.Desktop.Communication;VB.NETImports OpenNETCF.Desktop.Communication此外,还声明了一个模块变量 myrapi,该变量用于存储 RAPI 类的实例。VC#.NET/ 声明 RAPI 对象的实例。RAPI myrapi;VB.NET 声明 RAPI 对象的实例。Dim WithEvents myrapi As New rapi连接到设备桌面应用程序在使用 RAPI 类方法时,第一步是建立与设备的连接。注意:在桌面应用程序中使用 RAPI 要求在 PC 和设备之间激活 ActiveSync 连接。本文包含的应用程序示例在 Form_Load 事件中建立与设备的连接。要连接到设备,请使用 RAPI 类的 Connect 方法。如以下代码所示,紧接着检查 RAPI 类的 DevicePresent 属性,以验证连接是否成功。VC#.NETtry / 连接到设备。 myrapi.Connect(); while (! myrapi.DevicePresent) MessageBox.Show(Please connect your device to your PC using ActiveSync and before clicking the OK button., No Device Present); myrapi.Connect(); catch (Exception ex) MessageBox.Show(The following error occurred while attempting to connect to+ your device - + ex.Message, Connection Error); Application.Exit();VB.NETTry 连接到设备。 myrapi.Connect() Do While Not myrapi.DevicePresent MessageBox.Show(Please connect your device to your PC using ActiveSync and & _ before clicking the OK button., No Device Present) myrapi.Connect() LoopCatch ex As Exception MessageBox.Show(The following error occurred while attempting to connect to & _ your device - & ex.Message, Connection Error) Application.Exit()End Try建立连接后,准备使用 RAPI 提供的功能。首先,了解如何通过桌面应用程序管理设备的目录文件。使用文件RAPI 提供了相当多处理文件目录的功能。这里演示 3 种与文件有关的功能:将文件复制到设备或从设备复制文件、移动设备中的文件、删除设备中的文件。首先是复制文件。将文件复制到设备或从设备复制文件将数据移入或移出设备的一种最简单方法是,在 PC 和设备之间复制文本或 XML 文件。图 1 显示了使用 RAPI 演示程序的方法。在移动应用程序中,文本和基于 XML 的文件可作为一种简易方式存储应用程序数据或配置数据。图 1 : RAPI 演示程序的 “ 复制文件 ” 选项卡OpenNETCF.Desktop.Communication 命名空间的 RAPI 类提供了两种方法复制文件:CopyFileToDevice 和 CopyFileFromDevice。这两种方法都将源文件视作第一个变量,将目标文件视作第二个变量。btnCopyPerform 按钮的单击事件过程实现了这两种方法。究竟是调用 CopyFileToDevice 方法还是调用 CopyFileFromDevice 方法,取决于用户在用户界面组合框中选择的指令。VC#.NETprivate void btnCopyPerform_Click(object sender, System.EventArgs e) / 执行复制。 try if (txtCopySource.Text = ) | (txtCopyDestination.Text = ) MessageBox.Show(You must provide both a source and destination file., Missing File Information); else switch (cmbCopyDirection.Text) case : MessageBox.Show(You must select a direction before initiating the copy., No Destination Selected); break; case from desktop to device: myrapi.CopyFileToDevice(txtCopySource.Text, txtCopyDestination.Text); MessageBox.Show(Your file has been copied., Copy Success); break; case from device to desktop: myrapi.CopyFileFromDevice(txtCopySource.Text, txtCopyDestination.Text); MessageBox.Show(Your file has been copied., Copy Success); break; / 处理可能发生的所有错误。 catch (Exception ex) MessageBox.Show(The following error occurred copying the file - + ex.Message, Copy Error); VB.NETPrivate Sub btnCopyPerform_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopyPerform.Click 执行复制。 Try If (txtCopySource.Text = ) Or (txtCopyDestination.Text = ) Then MessageBox.Show(You must provide both a source and destination file., _ Missing File Information) Exit Sub End If Select Case cmbCopyDirection.Text Case MessageBox.Show(You must select a direction before initiating the copy., _ No Destination Selected) Exit Sub Case from desktop to device myrapi.CopyFileToDevice(txtCopySource.Text, txtCopyDestination.Text) Case from device to desktop myrapi.CopyFileFromDevice(txtCopySource.Text, txtCopyDestination.Text) End Select MessageBox.Show(Your file has been copied., Copy Success) 处理可能发生的所有错误。 Catch ex As Exception MessageBox.Show(The following error occurred copying the file - & ex.Message, _ Copy Error) End TryEnd Sub移动设备中的文件有时,您可能需要移动或重命名设备中的文件。例如,在将新版本文件复制到设备之前,可能要备份配置文件,图 2 显示了使用 RAPI 演示程序的方法。图 2 : RAPI 演示程序的 “ 移动文件 ” 选项卡OpenNETCF.Desktop.Communication 命名空间的 RAPI 类提供了 MoveDeviceFile方法来移动或重命名文件。和 CopyFile 方法一样,该方法也将源文件视作第一个变量,将目标文件视作第二个变量。btnMovePerform 按钮的单击事件过程实现了 MoveDeviceFile 方法。VC#.NETprivate void btnMovePerform_Click(object sender, System.EventArgs e)/ 执行移动。 try if (txtMoveSource.Text = ) | (txtMoveDestination.Text = ) MessageBox.Show(You must provide both a source and destination file., Missing File Information); else myrapi.MoveDeviceFile(txtMoveSource.Text, txtMoveDestination.Text); MessageBox.Show(Your file has been copied.,Copy Success); / 处理可能发生的所有错误。 catch (Exception ex) MessageBox.Show(The following error occurred moving the file + ex.Message,Connection Error); VB.NETPrivate Sub btnMovePerform_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMovePerform.Click 执行移动。 Try If (txtMoveSource.Text = ) Or (txtMoveDestination.Text = ) Then MessageBox.Show(You must provide both a source and destination file., _ Missing File Information) Exit Sub End If myrapi.MoveDeviceFile(txtMoveSource.Text, txtMoveDestination.Text) MessageBox.Show(Your file has been copied., Copy Success) 处理可能发生的所有错误。 Catch ex As Exception MessageBox.Show(The following error occurred moving the file - & ex.Message, _ Move Error) End TryEnd Sub删除设备中的文件很多时候,您会发现 RAPI 复制文件方法要与删除文件方法一同使用。例如,您可能要求桌面应用程序对应用程序用于存储设备数据的文件进行复制,然后在成功完成复制任务后,返回并从设备中删除文件,以便移动应用程序再次收集新的数据。图 3 显示了使用 RAPI 演示程序的方法。图 3 : RAPI 演示程序的 “ 删除文件 ” 选项卡OpenNETCF.Desktop.Communication 命名空间的 RAPI 类提供了 DeleteDeviceFile 方法来删除设备文件。要删除的文件是该方法的第一个变量。btnDeletePerform 按钮的单击事件过程实现了 DeleteDeviceFile 方法。VC#.NETprivate void btnDeletePerform_Click(object sender, System.EventArgs e)/ 执行删除。 try if (txtDeleteFile.Text = ) MessageBox.Show(You must provide a file to delete., No File Provided); else myrapi.DeleteDeviceFile(txtDeleteFile.Text); MessageBox.Show(Your fi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030儿童STEM教育行业市场现状与发展潜力评估报告
- 2025-2030二手车交易平台市场现状用户行为分析及商业模式优化研究报告
- 2025-2030中国预制菜产业市场规模与消费趋势深度研究报告
- 2025-2030中国青年公寓轻资产模式与重资产运营对比报告
- 2025-2030中国青年公寓市场空白点与增量机会分析报告
- 2025-2030中国青年公寓市场消费升级与投资趋势报告
- 2025-2030中国青年公寓市场存量资产盘活与价值提升报告
- 2025年大学消防指挥专业题库- 大学消防指挥专业实践报告撰写
- 咸阳市苹果产业发展:现状、困境与突破路径研究
- 和肾络颗粒:慢性肾衰竭微炎症状态的新希望
- 国企职工劳务合同协议
- GB/T 37507-2025项目、项目群和项目组合管理项目管理指南
- 商品检验试题及答案
- 骨科危重患者的急救及护理
- 2025年邮政社招笔试试题及答案
- 水资源保护课件
- 2025年中国移动初级解决方案经理学习考试题库大全-上(单选题)
- 重难点梳理写作指导(讲义)-人教PEP版英语六年级上册
- 临床用血管理制度课件
- 2024年钛行业发展研究报告
- 《人工智能通识教程》(第2版)教学大纲
评论
0/150
提交评论