我想在低连接区域中启用或禁用手机收音机。是否有可能做到这一点?我正在使用摩托罗拉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