Due to security reasons, your Windows Phone application is not
allowed to modify some of the device’s settings directly. For example, you
might want to programmatically turn on the airplane mode on the device.
However, this is not allowed without the user’s explicit permission. The only
way to turn on airplane mode is for the user to navigate to the Settings’s
Airplane Mode page and turn it on manually.
In your application, instead of asking the user to navigate to
the Settings page, you can directly bring them to the page, programmatically.
To launch the various Settings pages, you can use the Launcher class with the LaunchUriAsync() method. As you are
launching the pages asynchronously, you need to wrap these calls in a async method, like this:
private async void
LaunchSettings(int mode)
{
switch (mode)
{
case 0: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-airplanemode:"));
break;
case 1: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-bluetooth:"));
break;
case 2: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-cellular:"));
break;
case 3: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-wifi:"));
break;
case 4: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-location:"));
break;
case 5: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-emailandaccounts:"));
break;
case 6: await
Launcher.LaunchUriAsync(
new Uri("ms-settings-lock:"));
break;
}
}
The following figure shows the Airplane Mode settings page:
No comments:
Post a Comment