2

我能够在“aygshell.dll”上使用 p/invoke 来访问 Windows Mobile 6 中的电话声音配置文件,但 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);
   }
4

1 回答 1

1

Windows phone 7 的安全沙盒不允许开发人员访问将手机模式设置为静音或振动。充其量,该应用程序可以调出设置菜单,允许用户个人将手机设置为静音或振动模式。

于 2012-12-20T16:28:26.360 回答