Windows Phone APP中禁用截圖
Windows Phone 8 有系統(tǒng)自帶的截圖功能,快捷鍵:電源鍵+Win鍵,可以隨意截圖。
Windows Phone 更新GDR2后新增了一個(gè)隱藏功能,允許APP禁用截圖功能。
PhoneApplicationPage.IsScreenCaptureEnabled
這個(gè)隱藏的屬性需要通過(guò)反射來(lái)訪問(wèn)和修改狀態(tài)。
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); } }
}
調(diào)用CanSetScreenCaptureEnabled()方法檢測(cè)Windows Phone版本是否符合要求(version 8.0.10322以上)。符合條件,然后就通過(guò)擴(kuò)展方法GetScreenCaptureEnabled()和SetScreenCaptureEnabled()來(lái)修改PhoneApplicationPage.IsScreenCaptureEnabled屬性。
使用:
// 構(gòu)造函數(shù) public MainPage() { InitializeComponent(); if (this.CanSetScreenCaptureEnabled()) { this.SetScreenCaptureEnabled(false); } }
目前在真機(jī)(系統(tǒng)為WP8,WP8.1上效果如何不懂)上測(cè)試有效,沒(méi)弄懂模擬器如何像真機(jī)一樣截圖,所以模擬器上沒(méi)成。
效果如下圖

以后就有些東西不能截圖了( ╯□╰ )
對(duì)了,需要看原文的戳:Disabling screenshot functionality in a Windows Phone app 。
作者:十一_x
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。知識(shí)共享署名-非商業(yè)性使用-相同方式共享 2.5 中國(guó)大陸許可協(xié)議

浙公網(wǎng)安備 33010602011771號(hào)