{"id":13692289,"url":"https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity","last_synced_at":"2025-05-02T19:31:44.620Z","repository":{"id":167306536,"uuid":"629162759","full_name":"FabriBertani/Plugin.Maui.ScreenSecurity","owner":"FabriBertani","description":"Safeguard your .NET MAUI app effortlessly by preventing content exposure, screenshots, and recordings with ease.","archived":false,"fork":false,"pushed_at":"2024-12-31T17:33:52.000Z","size":724,"stargazers_count":179,"open_issues_count":2,"forks_count":15,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T23:38:53.181Z","etag":null,"topics":["android","ios","maui","mobile","net","protection","protector","screen","security","shield"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FabriBertani.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-17T18:51:20.000Z","updated_at":"2025-03-17T23:16:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0236790-2355-4df5-a8ec-bd131720d364","html_url":"https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity","commit_stats":null,"previous_names":["fabribertani/plugin.maui.screensecurity"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabriBertani%2FPlugin.Maui.ScreenSecurity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabriBertani%2FPlugin.Maui.ScreenSecurity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabriBertani%2FPlugin.Maui.ScreenSecurity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabriBertani%2FPlugin.Maui.ScreenSecurity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabriBertani","download_url":"https://codeload.github.com/FabriBertani/Plugin.Maui.ScreenSecurity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252095267,"owners_count":21693888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","ios","maui","mobile","net","protection","protector","screen","security","shield"],"created_at":"2024-08-02T17:00:55.860Z","updated_at":"2025-05-02T19:31:44.264Z","avatar_url":"https://github.com/FabriBertani.png","language":"C#","funding_links":[],"categories":["Components","Plugins"],"sub_categories":[],"readme":"# Plugin.Maui.ScreenSecurity\n[![NuGet](https://img.shields.io/nuget/v/Plugin.Maui.ScreenSecurity.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.Maui.ScreenSecurity)\n\n`Plugin.Maui.ScreenSecurity` provides a seamless solution for preventing content exposure, as well as blocking screenshots and recordings within your .NET MAUI application\n\n## Platforms supported\n|Platform|Version|\n|-------------------|:------------------:|\n|.Net MAUI Android|API 21+|\n|.Net MAUI iOS|iOS 14+|\n|Windows|10.0.17763+|\n\n## Version 1.2.0\n\n### What's new?\n- Added `IsProtectionEnabled` property to check if screen protection is already enabled or disabled.\n- Added `ScreenCaptured` event handler, which triggers notifications when a screenshot is taken or the screen is recorded.\n- Fixed iOS issues.\n- Added `Blazor` sample to showcase the implementation of this plugin.\n\nClick [here](https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity/releases/tag/v1.2.0) to see the full Changelog!\n\n## Installation\n`Plugin.Maui.ScreenSecurity` is available via NuGet, grab the latest package and install it on your solution:\n\n    Install-Package Plugin.Maui.ScreenSecurity\n\nInitialize the plugin in your `MauiProgram` class:\n\n```csharp\nusing Plugin.Maui.ScreenSecurity;\n\npublic static MauiApp CreateMauiApp()\n{\n    var builder = MauiApp.CreateBuilder();\n\n    builder\n        .UseMauiApp\u003cApp\u003e()\n        .ConfigureFonts(fonts =\u003e\n        {\n            fonts.AddFont(\"OpenSans-Regular.ttf\", \"OpenSansRegular\");\n            fonts.AddFont(\"OpenSans-Semibold.ttf\", \"OpenSansSemibold\");\n        })\n        .UseScreenSecurity();\n\n    return builder.Build();\n}\n```\n\n### Android\n\nIn your `Android.manifest` file (Platforms/Android) add the following permission:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.DETECT_SCREEN_CAPTURE\" /\u003e\n```\n\n### Using Plugin.Maui.ScreenSecurity\n\nFinally, add the default instance of the plugin as a singleton to inject it in your code late:\n\n```csharp\nbuilder.Services.AddSingleton\u003cIScreenSecurity\u003e(ScreenSecurity.Default);\n```\n## :warning:  WARNING  :warning:\nIt's important to acknowledge that preventing users from taking screenshots or recordings of your app can be a challenging task and achieving complete prevention may not be feasible. It's worth noting that no method can entirely eliminate the possibility of your screen being captured through another physical device or a potential breach in the OS.\n\n:point_right: It's also important to consider the impact on user experience when implementing any of these methods and striking a balance with the security concerns of your app.\n\n---\n\n## API Usage\n\u003e If you are still using version 1.0.0, please refer to the [Legacy docs](https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity/wiki/Legacy) for the previous version.\n\nThe new unified API includes two methods: `ActivateScreenSecurityProtection()` and `DeactivateScreenSecurityProtection()`, with optional parameters applicable only to the iOS platform. It also provides two properties: `IsProtectionEnabled`, which checks if protection is active, and the `ScreenCaptured` event handler, which notifies when a screenshot is taken or the screen is recorded.\n\n```csharp\nvoid ActivateScreenSecurityProtection();\n```\nWhen you activate this protection, your app's content will be safeguarded when it's sent to the Recents screen or the App Switcher. This helps ensure that sensitive information won't be exposed.\n\n### Behavior by platform:\n- **Android**: provides enhanced protection for screen content by preventing exposure when the app is sent to the _Background_ or displayed on the _Recents_ screen. It also effectively prevents unauthorized screenshots or recordings from being captured.\n- **Windows**: Prevents screenshots and recordings by obscuring the screen of the app.\n- **iOS**: By default, it apply a blur layer when the app is sent to the _Background_ or displayed on the _App Switcher_. Also enables the screenshot and screen recording protection.\n\n```csharp\nvoid ActivateScreenSecurityProtection(bool blurScreenProtection, bool preventScreenshot, bool preventScreenRecording);\n```\nThis method is similar to the previous method, but with parameters to change the default values in iOS:\n\n- **`blurScreenProtection`**: Enable/disable screen blurring to prevent content visibility in the background. **True** by default.\n- **`preventScreenshot`**: Decide whether users can take screenshots of your app. **True** by default.\n- **`preventScreenRecording`**: Control whether users can record the screen while using your app. **True** by default.\n\n```csharp\nvoid ActivateScreenSecurityProtection(ScreenProtectionOptions screenProtectionOptions);\n```\nThis method is similar to the original method, but takes a `ScreenProtectionOptions` parameter. This allows you to further customize the screen protection by specifying either a _Color_ or an _Image_, along with the the screenshot and screen recording protection for iOS devices.\n\n**Note**: If you set both _Color_ and _Image_, it will only apply the one you declared first.\n\n`ScreenProtectionOptions` properties:\n- **`Color`**: Represents a color in the form of a hexadecimal string and can be passed as an argument to customize the color layer. It supports formats such as `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA`. **Empty** by default.\n- **`Image`**: The name of the image file along with its extension. In order to utilize this property, please follow these steps:\n    - Save the image you intend to use inside the `Resources\\Images` folder.\n    - Ensure you refer to the [.Net MAUI Image documentation](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/image#load-a-local-image) for detailed instructions on how to accomplish this task effectively.\n    - :warning: If your app does not recognize the image after setting the build action to `MauiImage`, consider changing the build action to `Embedded resource` to ensure proper functionality.\n- **`PreventScreenshot`**: Decide whether users can take screenshots of your app. **True** by default.\n- **`PreventScreenRecording`**: Control whether users can record the screen while using your app. **True** by default.\n\n```csharp\nvoid DeactivateScreenSecurityProtection();\n```\nThis method deactivates all screen security protection.\n\n```csharp\nbool IsProtectionEnabled { get; }\n```\nThis bool checks if screen protection is enabled.\n\n```csharp\nevent EventHandler\u003cEventArgs\u003e? ScreenCaptured;\n```\nThe event handler is triggered when the screen is captured, either through a screenshot or recording on Android and iOS, **but only for screenshots on Windows**.\n\n## Usage Example\n\n```csharp\npublic partial class MainPage : ContentPage\n{\n    private readonly IScreenSecurity _screenSecurity;\n\n    public MainPage(IScreenSecurity screenSecurity)\n    {\n        InitializeComponent();\n\n        _screenSecurity = screenSecurity;\n    }\n\n    protected override void OnAppearing()\n    {\n        base.OnAppearing();\n\n        // Check if screen security protection is not enabled\n        if (!_screenSecurity.IsProtectionEnabled)\n        {\n            // Activate the screen security protection with default settings\n            _screenSecurity.ActivateScreenSecurityProtection();\n        }\n\n        // Attach to the ScreenCaptured event handler\n        _screenSecurity.ScreenCaptured += OnScreenCaptured;\n\n        /*\n        // For changing iOS options, follow one of the next examples:\n\n        // Example 1: Customize with a specific color\n        var screenProtectionOptions = new ScreenProtectionOptions\n        {\n            HexColor = \"#6C4675\",\n            PreventScreenshot = true,\n            PreventScreenRecording = false\n        };\n\n        // Example 2: Customize with an image\n        var screenProtectionOptions = new ScreenProtectionOptions\n        {\n            Image = \"protection_bg.png\"\n            PreventScreenshot = false,\n            PreventScreenRecording = true\n        };\n\n        _screenSecurity.ActivateScreenSecurityProtection(screenProtectionOptions);\n        */\n    }\n\n    protected override void OnDisappearing()\n    {\n        _screenSecurity.DeactivateScreenSecurityProtection();\n\n        // Detach from the ScreenCaptured event handler\n        _screenSecurity.ScreenCaptured -= OnScreenCaptured;\n\n        base.OnDisappearing();\n    }\n\n    private async void OnScreenCaptured(object sender, EventArgs e)\n    {\n        string title = \"ScreenSecuritySample\";\n        string message = \"Screen was captured by screenshot or recording.\";\n\n        await Shell.Current.DisplayAlert(title, message, \"Ok\");\n    }\n}\n```\n\n## Sample\nRefer to the [ScreenSecuritySample](https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity/tree/main/samples/ScreenSecuritySample) for a comprehensive and detailed implementation of this plugin, providing you with a complete understanding of its usage.\n\n## Contributions\nPlease feel free to open an [Issue](https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity/issues) if you encounter any bugs or submit a PR to contribute improvements or fixes. Your contributions are greatly appreciated.\n\n## License\nThe Plugin.Maui.ScreenSecurity is licensed under [MIT](https://github.com/FabriBertani/Plugin.Maui.ScreenSecurity/blob/main/LICENSE) license.\n\n## Contributors\n\n* **[Goran Karacic](https://github.com/Gogzs)** for the iOS 17 fix.\n* **[fabien367](https://github.com/fabien367)** for the iOS leak fix.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabriBertani%2FPlugin.Maui.ScreenSecurity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFabriBertani%2FPlugin.Maui.ScreenSecurity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabriBertani%2FPlugin.Maui.ScreenSecurity/lists"}