WinRT Tip - Add a Privacy Policy Link to the Settings Charm
April 22, 2013If a Windows 8 app declares network access in its capabilities, it is mandatory to have a privacy policy link in its application settings - like here.
If this privacy policy link is not present, your app will not make it through the Windows App Store certification process (like it just happened to me).
The question now is, how can we extend our app to have this privacy policy link in its application settings?
Registering with the Settings Pane
In your App.xaml.cs file add following code to the App class’s OnLaunched method.
1: SettingsPane.GetForCurrentView().CommandsRequested += (_, e) =>
2: {
3: e.Request.ApplicationCommands.Add(
4: new SettingsCommand("P", "Privacy Policy", OpenPrivacyPolicy));
5: };
Displaying the Policy
The only thing missing now is the implementation of the handler method for this ApplicationCommand we just created. In the following code snippet we navigate to a URI containing the privacy policy statement. But you could just as well display it in the application itself.
1: private async void OpenPrivacyPolicy(IUICommand command)
2: {
3: var uri = new Uri("/privacy");
4: await Launcher.LaunchUriAsync(uri);
5: }
Done.
Update
If you’re – like me - a fan of the classic one-liner, that’s how we do it:
1: SettingsPane.GetForCurrentView().CommandsRequested += (_, e) =>
2: e.Request.ApplicationCommands.Add(new SettingsCommand("P", "Privacy Policy", async __ =>
3: await Launcher.LaunchUriAsync(new Uri("/privacy"))));