2012-04-14 5 views
2

Ich konnte p/invoke auf "aygshell.dll" verwenden, um Telefon Soundprofile in Windows Mobile 6 zugreifen, aber Windows Phone 7 unterstützt den folgenden Code nicht. Gibt es einen Weg dahin? Ich möchte, dass meine App das Telefon im Ruhe- oder Vibrationsmodus einrichten kann.Zugriff auf den Ruhe-/Vibrationsmodus für Windows Phone 7 mit C#?

/*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); 
    } 
+0

Offenbar Windows Phone 7 erlaubt dies nicht, oder geben Sie den Entwicklern Zugriff auf die stillen/vibrieren Modi. – codingNinja

Antwort

1

Die Sicherheits-Sandbox von Windows Phone 7 ermöglicht Entwicklern keinen Zugriff auf Ruhemodus oder Vibration. Im besten Fall kann die App das Einstellungsmenü aufrufen, um es dem Benutzer zu ermöglichen, das Telefon persönlich in den Ruhe- oder Vibrationsmodus zu versetzen.