Windows phone 7 如何使用C#访问windows phone 7的静音/振动模式?
我可以使用“aygshell.dll”上的p/invoke访问WindowsMobile 6中的手机声音配置文件,但WindowsPhone 7不支持以下代码。有办法解决这个问题吗?我希望我的应用程序能够将手机设置为静音或振动模式Windows phone 7 如何使用C#访问windows phone 7的静音/振动模式?,windows-phone-7,silent,vibration,Windows Phone 7,Silent,Vibration,我可以使用“aygshell.dll”上的p/invoke访问WindowsMobile 6中的手机声音配置文件,但WindowsPhone 7不支持以下代码。有办法解决这个问题吗?我希望我的应用程序能够将手机设置为静音或振动模式 /*The following code works perfectly well with windows moblile 6.0 but fails for windows phone 7 at runtime. */ public enum SN
/*The following code works perfectly well with windows moblile 6.0 but fails for
windows phone 7 at runtime. */
public enum SND_SOUNDTYPE
{
On,
File,
Vibrate,
None
}
private enum SND_EVENT
{
All,
RingLine1,
RingLine2,
KnownCallerLine1,
RoamingLine1,
RingVoip
}
//Marshals
[StructLayout(LayoutKind.Sequential)]
private struct SNDFILEINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szPathName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
public SND_SOUNDTYPE sstType;
}
//p/invoke
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndSetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo, bool fSuppressUI);
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndGetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo);
//method to set ringer on
private static void SetProfileNormal()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.On;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer to vibrate
private static void SetProfileVibrate()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.Vibrate;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer off - silent mode
private static void SetProfileMuted()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.None;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to check if phone is in vibrate mode
private bool IsInVibrateMode()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.Vibrate);
}
//method to check if phone is in silent mode
private bool IsMuted()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.None);
}
Windows phone 7的安全沙箱不允许开发人员将手机模式设置为静音或振动。充其量,该应用程序可以打开“设置”菜单,允许用户亲自将手机设置为静音或振动模式。显然,windows phone 7不允许这样做,或者允许开发者访问静音/振动模式。
/*The following code works perfectly well with windows moblile 6.0 but fails for
windows phone 7 at runtime. */
public enum SND_SOUNDTYPE
{
On,
File,
Vibrate,
None
}
private enum SND_EVENT
{
All,
RingLine1,
RingLine2,
KnownCallerLine1,
RoamingLine1,
RingVoip
}
//Marshals
[StructLayout(LayoutKind.Sequential)]
private struct SNDFILEINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szPathName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
public SND_SOUNDTYPE sstType;
}
//p/invoke
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndSetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo, bool fSuppressUI);
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndGetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo);
//method to set ringer on
private static void SetProfileNormal()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.On;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer to vibrate
private static void SetProfileVibrate()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.Vibrate;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer off - silent mode
private static void SetProfileMuted()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.None;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to check if phone is in vibrate mode
private bool IsInVibrateMode()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.Vibrate);
}
//method to check if phone is in silent mode
private bool IsMuted()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.None);
}