明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

桌面端的移動(dòng)計(jì)算(4)

[摘要]Launching an Application有很多原因使你要從一個(gè)桌面程序啟動(dòng)設(shè)備上的一個(gè)應(yīng)用程序。在下面情況下,你可以使用這個(gè)技術(shù):· 安裝一...
Launching an Application
有很多原因使你要從一個(gè)桌面程序啟動(dòng)設(shè)備上的一個(gè)應(yīng)用程序。在下面情況下,你可以使用這個(gè)技術(shù):

· 安裝一個(gè)新版本的應(yīng)用程序。簡(jiǎn)單地拷貝CAB文件到設(shè)備上,然后在設(shè)備上運(yùn)行CAB安裝程序來(lái)提供安裝。這項(xiàng)技術(shù)被經(jīng)常用在你想自動(dòng)發(fā)布和安裝應(yīng)用程序更新的情況下。

注意 另一個(gè)相似的發(fā)法是自動(dòng)話桌面端的安裝過(guò)程,使用ActiveSync內(nèi)置的功能。

· 在安裝了新版本應(yīng)用程序后重起你的移動(dòng)應(yīng)用程序。

· 開(kāi)始一個(gè)設(shè)備應(yīng)用程序處理新更新的數(shù)據(jù),在更新了文本或者XML文件后。

RAPI示例程序如圖4。


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

OpenNETCF.Desktop.Communication命名空間RAPI類提供CreateProcess方法來(lái)啟動(dòng)一個(gè)設(shè)備文件。你希望啟動(dòng)的設(shè)備應(yīng)用程序作為該方法的第一個(gè)參數(shù)。你可以傳遞一個(gè)命令行給應(yīng)用程序,作為第二個(gè)參數(shù)。

btnLaunchPerform按鈕的點(diǎn)擊事件演示了CreateProcess方法。

[VC#.NET]
private void btnLaunchPerform_Click(object sender, System.EventArgs e)
{

// Perform the launch.
try
{
if (txtLaunchFile.Text == "")
{
MessageBox.Show("You must provide a file to launch.",
"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 = "") ThenMessageBox.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接下來(lái)我們將進(jìn)入最后一個(gè)RAPI有關(guān)的主題:獲得系統(tǒng)信息。在下面的部分你將看到,RAPI類提供了一些方法用來(lái)得到連接設(shè)備的詳細(xì)信息。Retrieving System Information得到指定的設(shè)備系統(tǒng)信息使你的程序能夠在下面幾個(gè)方面交付內(nèi)容或改變功能:· 連接設(shè)備上使用的處理器,當(dāng)應(yīng)用程序上傳一個(gè)包含指定處理器的文件的CAB文件到設(shè)備上時(shí)。注意 這項(xiàng)技術(shù)最常用的環(huán)境是當(dāng)你發(fā)布應(yīng)用程序到早期版本的Pocket PC設(shè)備上,例如基于ARM處理器的Windows Mobile設(shè)備! 運(yùn)行在連接設(shè)備上的操作系統(tǒng)版本,根據(jù)處理器類型使用相應(yīng)文件進(jìn)行更新! 連接設(shè)備的電源狀態(tài),經(jīng)常用于在使用者進(jìn)入?yún)^(qū)域前,警告他們的設(shè)備運(yùn)行于低電量狀態(tài)下! 連接設(shè)備的內(nèi)存狀態(tài),用于檢測(cè)數(shù)據(jù)是否可以下載,如果用戶下載了未被授權(quán)的應(yīng)用程序或者其他內(nèi)存相關(guān)函數(shù),或者判斷你是否有足夠的空間安裝應(yīng)用程序的更新。這部分操作的演示界面見(jiàn)圖5。Figure 5. The Device Information tab of the RAPI demo programRAPI類提供了四個(gè)方法來(lái)得到這些信息,GetDeviceSystemInfo (處理器類型), GetDeviceVersion (操作系統(tǒng)版本), GetDeviceSystemPowerStatus (電源狀態(tài)) 和 GetDeviceMemoryStatus (內(nèi)存).BtnInfoRetrieve按鈕的點(diǎn)擊事件示范了這些方法。[VC#.NET]private void btnInfoRetrieve_Click(object sender, System.EventArgs e){ string info; MEMORYSTATUS ms; SYSTEM_INFO si; SYSTEM_POWER_STATUS_EX sps; OSVERSIONINFO vi; // Retrieve the system information. myrapi.GetDeviceSystemInfo(out si); // Retrieve the device OS version number. myrapi.GetDeviceVersion(out vi); // Retrieve the device power status. myrapi.GetDeviceSystemPowerStatus(out sps); // Retrieve the device memory status. myrapi.GetDeviceMemoryStatus(out ms); // Format the retrieved information. info = "The connected device has an "; switch (si.wProcessorArchitecture) { case ProcessorArchitecture.Intel: info += "Intel processor.\n"; break; case ProcessorArchitecture.MIPS: info += "MIPS processor.\n"; break; case ProcessorArchitecture.ARM: info += "ARM processor.\n"; break; default: info = "unknown processor type.\n"; break; } info += "OS version: " + vi.dwMajorVersion + "." +
vi.dwMinorVersion + "." + vi.dwBuildNumber + "\n"; if (sps.ACLineStatus == 1) { info += "On AC power: YES\n"; } else { info += "On AC power: NO \n"; } info += "Battery level: " + sps.BatteryLifePercent + "%\n"; info += "Total memory: " + String.Format("{0:###,###,###}",
ms.dwTotalPhys) + "\n"; // Display the results. lblInfo.Text = info; }[VB.NET]Private Sub btnInfoRetrieve_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnInfoRetrieve.Click Dim info As String Dim ms As New MEMORYSTATUS Dim si As New SYSTEM_INFO Dim sps As New SYSTEM_POWER_STATUS_EX Dim vi As New OSVERSIONINFO ' Retrieve the system information. myrapi.GetDeviceSystemInfo(si) ' Retrieve the device OS version number. myrapi.GetDeviceVersion(vi) ' Retrieve the device power status. myrapi.GetDeviceSystemPowerStatus(sps) ' Retrieve the device memory status. myrapi.GetDeviceMemoryStatus(ms) ' Format the retrieved information. info = "The connected device has an " Select Case si.wProcessorArchitecture Case ProcessorArchitecture.Intel info += "Intel processor." & vbCrLf Case ProcessorArchitecture.MIPS info += "MIPS processor." & vbCrLf Case ProcessorArchitecture.ARM info += "ARM processor." & vbCrLf Case Else info = "unknown processor type." & vbCrLf End Select info += "OS version: " & vi.dwMajorVersion & "." & vi.dwMinorVersion
& "." & vi.dwBuildNumber & vbCrLf info += "On AC power: " & IIf(sps.ACLineStatus = 1, "YES", "NO")
& vbCrLf info += "Battery level: " & sps.BatteryLifePercent & "%" & vbCrLf info += "Total memory: " & String.Format("{0:###,###,###}",
ms.dwTotalPhys) & vbCrLf ' Display the results. lblInfo.Text = info End Sub到這里我們?nèi)绻麑⒆烂鎽?yīng)用程序加入到你的移動(dòng)解決方案和關(guān)于Remote API的介紹就要告以段落了。我建議你花一些時(shí)間來(lái)檢驗(yàn)OpenNETCF.Desktop.Communication命名空間提供的其他的功能。記住,那才是所有的操作,OpenNETCF命名空間為你的應(yīng)用程序提供了多種類的操作。Back on the Road又是一個(gè)新的月份了。春天已經(jīng)來(lái)到了每個(gè)角落,我要帶著我的滑水板和Pocket PC前往陽(yáng)光充足的Florida。在我的下一篇文章里,我們將檢驗(yàn)關(guān)于移動(dòng)開(kāi)發(fā)者更多的操作。