Windows Phone APP中禁用截圖


Windows Phone 8 有系統自帶的截圖功能,快捷鍵:電源鍵+Win鍵,可以隨意截圖。

Windows Phone 更新GDR2后新增了一個隱藏功能,允許APP禁用截圖功能。

PhoneApplicationPage.IsScreenCaptureEnabled

 這個隱藏的屬性需要通過反射來訪問和修改狀態。

 public static  class PhoneApplicationPageExtensionMethods
    {

    public
static bool CanSetScreenCaptureEnabled(this PhoneApplicationPage page) { return Environment.OSVersion.Version >= new Version(8, 0, 10322); } public static void SetScreenCaptureEnabled(this PhoneApplicationPage page, bool enabled) { var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled"); if (propertyInfo == null) { throw new NotSupportedException("Not supported in this Windows Phone version!"); } propertyInfo.SetValue(page, enabled); } public static bool GetScreenCaptureEnabled(this PhoneApplicationPage page) { var propertyInfo = typeof(PhoneApplicationPage).GetProperty("IsScreenCaptureEnabled"); if (propertyInfo == null) { throw new NotSupportedException("Not supported in this Windows Phone version!"); } return (bool)propertyInfo.GetValue(page); } }
}

調用CanSetScreenCaptureEnabled()方法檢測Windows Phone版本是否符合要求(version 8.0.10322以上)。符合條件,然后就通過擴展方法GetScreenCaptureEnabled()和SetScreenCaptureEnabled()來修改PhoneApplicationPage.IsScreenCaptureEnabled屬性。
使用:

      // 構造函數
        public MainPage()
        {
            InitializeComponent();

            if (this.CanSetScreenCaptureEnabled())
            {
                this.SetScreenCaptureEnabled(false);
            }
        }

目前在真機(系統為WP8,WP8.1上效果如何不懂)上測試有效,沒弄懂模擬器如何像真機一樣截圖,所以模擬器上沒成。

效果如下圖

 

以后就有些東西不能截圖了( ╯□╰ )

 對了,需要看原文的戳:Disabling screenshot functionality in a Windows Phone app  。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM