桌面端的移动计算(四)

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Launching an Application

有很多原因使你要从一个桌面程序启动设备上的一个应用程序。在下面情况下,你可以使用这个技术:

· 安装一个新版本的应用程序。简单地拷贝CAB文件到设备上,然后在设备上运行CAB安装程序来提供安装。这项技术被经常用在你想自动发布和安装应用程序更新的情况下。

注意 另一个相似的发法是自动话桌面端的安装过程,使用ActiveSync内置的功能。

· 在安装了新版本应用程序后重起你的移动应用程序。

· 开始一个设备应用程序处理新更新的数据,在更新了文本或者XML文件后。

RAPI示例程序如图4

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 292.5pt; HEIGHT: 178.5pt" type="#_x0000_t75" alt=""><img src="/Develop/ArticleImages/27/27155/CSDN_Dev_Image_2004-4-231744520.gif" o:href="http://msdn.microsoft.com/library/en-us/dnroad/html/road0324200404.gif"><font face="宋体"></font></shape>

Figure 4. The Launch Application tab of the RAPI demo program

OpenNETCF.Desktop.Communication命名空间RAPI类提供CreateProcess方法来启动一个设备文件。你希望启动的设备应用程序作为该方法的第一个参数。你可以传递一个命令行给应用程序,作为第二个参数。

btnLaunchPerform按钮的点击事件演示了CreateProcess方法。

 else

 {

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);

 MessageBox.Show("Your file has been launched.", "Launch Success");

 }

 }

 

// Handle any errors that might occur.

 catch (Exception ex)

 {

 MessageBox.Show("The following error occurred while launching the 
file -" +

 ex.Message, "Launch Error");

 } 

}

[VB.NET]

Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click

' Perform the launch.

 Try

 If (txtLaunchFile.Text = "") Then

MessageBox.Show("You must provide a file to launch.", _ "No File Provided");

 }

 else

 "No File Provided");

 }

 else

 {

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);

 MessageBox.Show("Your file has been launched.", "Launch Success");

 }

 }

 

// Handle any errors that might occur.

 catch (Exception ex)

 {

 MessageBox.Show("The following error occurred while launching the 
file -" +

 ex.Message, "Launch Error");

 } 

}

[VB.NET]

Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click

' Perform the launch.

 Try

 If (txtLaunchFile.Text = "") Then

 MessageBox.Show("You must provide a file to launch.", _

 "No File Provided")

 Exit Sub

 End If

 myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text)

 MessageBox.Show("Your file has been launched.", "Launch Success")

' Handle any errors that might occur.

 Catch ex As Exception

 MessageBox.Show("The following error occurred while launching the file
-" & ex.Message, _

 "Launch Error")

 End Try

End Sub

接下来我们将进入最后一个RAPI有关的主题:获得系统信息。在下面的部分你将看到,RAPI类提供了一些方法用来得到连接设备的详细信息。

Retrieving System Information

得到指定的设备系统信息使你的程序能够在下面几个方面交付内容或改变功能:

· 连接设备上使用的处理器,当应用程序上传一个包含指定处理器的文件的CAB文件到设备上时。

注意 这项技术最常用的环境是当你发布应用程序到早期版本的Pocket PC设备上,例如基于ARM处理器的Windows Mobile设备。

· 运行在连接设备上的操作系统版本,根据处理器类型使用相应文件进行更新。

· 连接设备的电源状态,经常用于在使用者进入区域前,警告他们的设备运行于低电量状态下。

· 连接设备的内存状态,用于检测数据是否可以下载,如果用户下载了未被授权的应用程序或者其他内存相关函数,或者判断你是否有足够的空间安装应用程序的更新。

这部分操作的演示界面见图5

<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 292.5pt; HEIGHT: 178.5pt" type="#_x0000_t75" alt=""><img src="/Develop/ArticleImages/27/27155/CSDN_Dev_Image_2004-4-231744520.gif" o:href="http://msdn.microsoft.com/library/en-us/dnroad/html/road0324200405.gif"><font face="宋体"></font></shape>

Figure 5. The Device Information tab of the RAPI demo program

RAPI类提供了四个方法来得到这些信息,GetDeviceSystemInfo (处理器类型), GetDeviceVersion (操作系统版本), GetDeviceSystemPowerStatus (电源状态) GetDeviceMemoryStatus (内存).

BtnInfoRetrieve按钮的点击事件示范了这些方法。

到这里我们如果将桌面应用程序加入到你的移动解决方案和关于Remote API的介绍就要告以段落了。我建议你花一些时间来检验OpenNETCF.Desktop.Communication命名空间提供的其他的功能。记住,那才是所有的操作,OpenNETCF命名空间为你的应用程序提供了多种类的操作。

Back on the Road

又是一个新的月份了。春天已经来到了每个角落,我要带着我的滑水板和Pocket PC前往阳光充足的Florida。在我的下一篇文章里,我们将检验关于移动开发者更多的操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值