我想在低連接區域中啓用或禁用手機收音機。是否有可能做到這一點?我正在使用摩托羅拉ES400進行開發。在windows mobile中禁用或啓用手機收音機6.5.3
1
A
回答
1
您需要P/Invoke GetDeviceList
和ChangeRadioState
從ossvcs.dll
。實際執行此操作的代碼對於SO帖子來說有點長,所以我會留給你,讓它解決 - 這不是非常困難(有一些C code here,甚至有一些C# code on CodeProject,我沒有用過它所以YMMV)。
另一種選擇是在SDF中使用Radios
類,它已包含這些類。
2
第一:導入這些DLL
[DllImport("ossvcs.dll", EntryPoint = "#276", CharSet = CharSet.Unicode)]
private static extern uint GetWirelessDevice(ref IntPtr pDevice, int pDevVal);
[DllImport("ossvcs.dll", EntryPoint = "#273", CharSet = CharSet.Unicode)]
private static extern uint ChangeRadioState(ref RDD pDevice, int dwState, int saveAction);
[DllImport("ossvcs.dll", EntryPoint = "#280", CharSet = CharSet.Unicode)]
private static extern uint FreeDeviceList(IntPtr pDevice);
下面是我使用的摩托羅拉MC65,這應該爲你的工作以及代碼的副本。
[StructLayout(LayoutKind.Auto)]
struct RADIODEVSTATE
{
public const int RADIODEVICES_ON = 1;
public const int RADIODEVICES_OFF = 0;
}
/*
typedef enum _RADIODEVTYPE
{
RADIODEVICES_MANAGED = 1,
RADIODEVICES_PHONE,
RADIODEVICES_BLUETOOTH,
} RADIODEVTYPE;
*/
[StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)]
struct RADIODEVTYPE
{
public const int RADIODEVICES_MANAGED = 1;
public const int RADIODEVICES_PHONE = 2;
public const int RADIODEVICES_BLUETOOTH = 3;
}
/*
typedef enum _SAVEACTION
{
RADIODEVICES_DONT_SAVE = 0,
RADIODEVICES_PRE_SAVE,
RADIODEVICES_POST_SAVE,
} SAVEACTION;
*/
[StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)]
struct SAVEACTION
{
public const int RADIODEVICES_DONT_SAVE = 0;
public const int RADIODEVICES_PRE_SAVE = 1;
public const int RADIODEVICES_POST_SAVE = 2;
}
/*
struct RDD
{
RDD() : pszDeviceName(NULL), pNext(NULL), pszDisplayName(NULL) {}
~RDD() { LocalFree(pszDeviceName); LocalFree(pszDisplayName); }
LPTSTR pszDeviceName; // Device name for registry setting.
LPTSTR pszDisplayName; // Name to show the world
DWORD dwState; // ON/off/[Discoverable for BT]
DWORD dwDesired; // desired state - used for setting registry etc.
RADIODEVTYPE DeviceType; // Managed, phone, BT etc.
RDD * pNext; // Next device in list
}; //radio device details
*/
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct RDD
{
[MarshalAs(UnmanagedType.LPTStr)]
public string pszDeviceName;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszDisplayName;
public uint dwState;
public uint dwDesired;
public int DeviceType;
public IntPtr pNext;
}
private static bool SetDeviceState(int dwDevice, int dwState)
{
var pDevice = new IntPtr(0);
//Get the first wireless device
var result = GetWirelessDevice(ref pDevice, 0);
if (result != 0)
return false;
//While we're still looking at wireless devices
while (pDevice != IntPtr.Zero)
{
//Marshall the pointer into a C# structure
var device = (RDD)System.Runtime.InteropServices.Marshal.PtrToStructure(pDevice, typeof(RDD));
//If this device is the device we're looking for
if (device.DeviceType == dwDevice)
{
//Change the state of the radio
result = ChangeRadioState(ref device, dwState, SAVEACTION.RADIODEVICES_PRE_SAVE);
}
//Set the pointer to the next device in the linked list
pDevice = device.pNext;
}
//Free the list of devices
FreeDeviceList(pDevice);
//Turning off radios doesn't correctly report the status, so return true anyway.
return result == 0 || dwState == RADIODEVSTATE.RADIODEVICES_OFF;
}
並關掉手機只需撥打下面的方法:
/// <summary>
/// Disables the phone radio on device
/// </summary>
public void DisablePhoneRadio()
{
SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_OFF);
}
所以只使用需要什麼條件語句,並調用DisablePhoneRadio()每當你需要禁用它,使手機時無線電只是撲打了與RADIODEVSTATE.RADIODEVICES_ON的RADIODEVSTATE.RADIODEVICES_OFF像這樣:
/// <summary>
/// Enables the phone radio on device
/// </summary>
public void EnablePhoneRadio()
{
SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_ON);
}
希望這有助於!
0
檢查此主題以及。有趣的事情發生在線程調用和監視設備連接狀態以及在Windows Mobile上打開和關閉蜂窩無線電。
http://www.codeproject.com/Messages/4117749/Re-Csharp-Wrapper.aspx
從下面的答案相關問題
- 1. Android在xml中禁用收音機組
- 2. 在Windows Mobile 6.5.3中禁用SmartMinimize硬按鈕/確定硬按鈕
- 3. 在手機上禁用音頻背景
- 4. Windows Mobile 6.5.3中的CustomListView
- 5. 在手機中禁用手機後退按鈕[和jQuery手機
- 6. 使用GPS的Windows Mobile手機
- 7. 在Windows Mobile手機中籤名捕獲?
- 8. Windows Mobile:用C#使用手機的相機
- 9. Windows Mobile 6.5.3預處理器
- 10. windows手機和聲音雲
- 11. 如何禁用Windows手機鍵盤?
- 12. jQuery Mobile的changePage()無法在Windows手機
- 13. 在Windows 10手機中接收廣播
- 14. Windows Mobile-手機的相機應用程序(C#)
- 15. 啓動Windows錄音機應用程序
- 16. 爲手機禁用腳本
- 17. 如何禁用和啓用在jQuery手機中選擇
- 18. 在Xperia智能手機中禁用/啓用擴展待機模式
- 19. 在手機上啓用prettyphoto
- 20. 自動啓動Datawedge在MC65運行Windows Mobile 6.5.3
- 21. 開發Windows Mobile手機,無合同
- 22. .addClass不能用收音機
- 23. 檢測手機或Windows PHP
- 24. 禁用webOS手機鏈接
- 25. 在Windows手機上啓動geotracking
- 26. jQuery手動設置buttonset收音機
- 27. 如果選中收音機,請禁用選擇表單
- 28. jQuery手機:在ListViews中啓用Word Wrap
- 29. 刷新輸入:從iframe使用Jquery Mobile的收音機
- 30. 如何在Windows 10手機模擬器中啓用藍牙?
除此之外,另一種選擇是使用供應商的設備SDK(其中摩托羅拉稱他們EMDK)。 – tcarvin