Question

I was able to use p/invoke on "aygshell.dll" to access phone sound profiles in windows mobile 6 but Windows Phone 7 does not support the following code. Is there a way around this? I want my app to be able to set the phone in silent or vibrate mode.

/*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);
   }
Was it helpful?

Solution

Windows phone 7's security sandbox does not allow developer access to set phone modes to silent or vibrate. At best, the app can bring up the settings menu to allow the user to personally set the phone in silent or vibrate mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top