Skip to content

Commit

Permalink
Windows 11 Version 22H2 - May 2024 Samples Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed May 16, 2024
1 parent bd31b44 commit 0db108e
Show file tree
Hide file tree
Showing 182 changed files with 1,457 additions and 15,298 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,17 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
<tr>
<td><a href="Samples/Personalization">Lock screen personalization</a></td>
<td><a href="Samples/MicrosoftPassport">Microsoft Passport and Windows Hello</a></td>
<td><a href="Samples/SmartCard">Smart cards</a></td>
<td><a href="Samples/PersonalDataEncryption">Personal Data Encryption</a></td>
</tr>
<tr>
<td><a href="Samples/SmartCard">Smart cards</a></td>
<td><a href="Samples/UserInfo">User information</a></td>
<td><a href="Samples/UserCertificateStore">UserCertificateStore</a></td>
<td><a href="Samples/UserConsentVerifier">UserConsentVerifier</a></td>
</tr>
<tr>
<td><a href="Samples/WebAccountManagement">Web account management</a></td>
<td><a href="Samples/WebAuthenticationBroker">WebAuthenticationBroker</a></td>
<td><a href="Samples/UserConsentVerifier">UserConsentVerifier</a></td>
</tr>
</table>

Expand Down
64 changes: 31 additions & 33 deletions Samples/Geolocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,66 @@ and track when the location changes in various ways.

After obtaining access to the user's location, an app can

* Retrieve the current location.
* Receiving events when the location changes.
* Receiving events when the device has entered or exited locations of interest.
* Receiving events when the device has spent significant time in a location (a "visit").
- Retrieve the current location.
- Receiving events when the location changes.
- Receiving events when the device has entered or exited locations of interest.
- Receiving events when the device has spent significant time in a location (a "visit").

> **Note:** This sample is part of a large collection of UWP feature samples.
> **Note:** This sample is part of a large collection of UWP feature samples.
> You can download this sample as a standalone ZIP file
> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/geolocation/),
> or you can download the entire collection as a single
> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/master.zip), but be
> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.
> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/master.zip), but be
> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file,
> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq).
> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center.
This sample also shows how to:

- **Use a [geofence](http://msdn.microsoft.com/library/windows/apps/dn263744):** Receive notifications when the user's device has entered or left an area of interest.
- **Handle changes in location permissions**: Register for the Geolocator's StatusChanged event and use the [StatusChangedEventArgs](http://msdn.microsoft.com/library/windows/apps/br225600) to determine the current position status.
- **Get location from a background task**
- **Handle geofencing events from a background task**
- **Handle geovisit events from a background task**
- **Obtain satellite data:** When available, use the [GeocoordinateSatelliteData](http://msdn.microsoft.com/library/windows/apps/jj635260) class to obtain additional information on the quality of the satellite based location data.
- **Display a toast:** Notify the user when a geofencing event has occurred in the background.
- **Refresh geofence binding:** Refresh the binding on resume and after removal of a geofence. Note that removal requires subscribing to removal events if a geofence is set as single use or a duration is set.
- **Use a [geofence](http://msdn.microsoft.com/library/windows/apps/dn263744):** Receive notifications when the user's device has entered or left an area of interest.
- **Handle changes in location permissions**: Register for the Geolocator's StatusChanged event and use the [StatusChangedEventArgs](http://msdn.microsoft.com/library/windows/apps/br225600) to determine the current position status.
- **Get location from a background task**
- **Handle geofencing events from a background task**
- **Handle geovisit events from a background task**
- **Obtain satellite data:** When available, use the [GeocoordinateSatelliteData](http://msdn.microsoft.com/library/windows/apps/jj635260) class to obtain additional information on the quality of the satellite based location data.
- **Display a toast:** Notify the user when a geofencing event has occurred in the background.
- **Refresh geofence binding:** Refresh the binding on resume and after removal of a geofence. Note that removal requires subscribing to removal events if a geofence is set as single use or a duration is set.
- **Request access to the user's location:** Request access to the user's location using the RequestAccessAsync method. Important: call the RequestAccessAsync before accessing the user's location. At that time, your app must be in the foreground and RequestAccessAsync must be called from the UI thread. Until the user grants your app permission to their location, your app can't access location data.
- **Track when the user visits a location:** Poll for or receive notifications when the user spends significant time in a location.
- **Track when the user visits a location:** Poll for or receive notifications when the user spends significant time in a location.
- **Help the user change location settings:** Link to location privacy settings from your app if the user revokes access to location while your app is in the foreground. Call the LaunchUriAsync method with the URI "ms-settings://privacy/location".

Geofences need to be created in the Foreground Geofencing scenario (Scenario 4) and then you can go to Background Geofencing scenario (Scenario 5) to register for background geofencing events.
Geofences need to be created in the foreground geofencing scenario (Scenario 4) and then you can go to background geofencing scenario (Scenario 5) to register for background geofencing events.

The Geolocation sample formats and parses time and dates in the en-US locale using the Gregorian calendar and 24-hour clock. To help other locales in entering data the edit fields have a format example shown below the control. For example, Start Time would be entered mm/dd/yyyy hh:mm:ss format. February 2, 2014 at 10:34 pm would be written 2/2/2014 22:34:00. For the Dwell Time and Duration the format is dd:hh:mm:ss so a time span of 7 days, 23 hours, 45 minutes and 55 seconds would be written as 7:23:45:55.
The Geolocation sample formats and parses time and dates in the en-US locale using the Gregorian calendar and 24-hour clock. To help other locales in entering data the edit fields have a format example shown below the control. For example, Start Time would be entered mm/dd/yyyy hh:mm:ss format. February 2, 2014 at 10:34 pm would be written 2/2/2014 22:34:00. For the Dwell Time and Duration the format is dd:hh:mm:ss so a time span of 7 days, 23 hours, 45 minutes and 55 seconds would be written as 7:23:45:55.

### Declaring the Location capability
## Declaring the Location capability

This sample requires that location capability be set in the *Package.appxmanifest* file to allow the app to access location at runtime. The capability can be set in the app manifest using Microsoft Visual Studio.


## Related topics

### Conceptual

* [Get current location](https://msdn.microsoft.com/library/windows/apps/mt219698)
* [Guidelines for location-aware apps](https://msdn.microsoft.com/library/windows/apps/hh465148)
- [Get current location](https://msdn.microsoft.com/library/windows/apps/mt219698)
- [Guidelines for location-aware apps](https://msdn.microsoft.com/library/windows/apps/hh465148)

### Reference

* [Windows.Devices.Geolocation](http://msdn.microsoft.com/library/windows/apps/br225603)
* [Windows.Devices.Geolocation.Geofencing](https://msdn.microsoft.com/library/windows/apps/dn263744)
- [Windows.Devices.Geolocation](http://msdn.microsoft.com/library/windows/apps/br225603)
- [Windows.Devices.Geolocation.Geofencing](https://msdn.microsoft.com/library/windows/apps/dn263744)

### Related samples

* [Traffic App sample](https://github.com/microsoft/windows-appsample-trafficapp/)
* [Lunch Scheduler app sample](https://github.com/Microsoft/Windows-appsample-lunch-scheduler)
* [Geolocation sample](/archived/Geolocation/) for C++/CX and JavaScript (archived)
- [Traffic App sample](https://github.com/microsoft/windows-appsample-trafficapp/)
- [Lunch Scheduler app sample](https://github.com/Microsoft/Windows-appsample-lunch-scheduler)

## System requirements

* Windows 10
- Requires Windows SDK 10.0.22621.0 to build and Windows 10 to run.

## Build the sample

1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file.
4. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**.
Expand All @@ -99,8 +97,8 @@ The next steps depend on whether you just want to deploy the sample or you want

### Deploying the sample

- Select Build > Deploy Solution.
- Select Build > Deploy Solution.

### Deploying and running the sample

- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging.
- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging.
3 changes: 3 additions & 0 deletions Samples/Geolocation/cppwinrt/Scenario1_TrackPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "pch.h"
#include "Scenario1_TrackPosition.h"
#include "Scenario1_TrackPosition.g.cpp"
#include "SampleConfiguration.h"

using namespace winrt;
using namespace winrt::Windows::Devices::Geolocation;
Expand Down Expand Up @@ -173,13 +174,15 @@ namespace winrt::SDKTemplate::implementation
ScenarioOutput_Latitude().Text(L"No data");
ScenarioOutput_Longitude().Text(L"No data");
ScenarioOutput_Accuracy().Text(L"No data");
ScenarioOutput_Source().Text(L"No data");
ScenarioOutput_IsRemoteSource().Text(L"No data");
}
else
{
ScenarioOutput_Latitude().Text(to_hstring(position.Coordinate().Point().Position().Latitude));
ScenarioOutput_Longitude().Text(to_hstring(position.Coordinate().Point().Position().Longitude));
ScenarioOutput_Accuracy().Text(to_hstring(position.Coordinate().Accuracy()));
ScenarioOutput_Source().Text(to_hstring(position.Coordinate().PositionSource()));
ScenarioOutput_IsRemoteSource().Text(to_hstring(position.Coordinate().IsRemoteSource()));
}
}
Expand Down
38 changes: 29 additions & 9 deletions Samples/Geolocation/cs/Geolocation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UAP</DefineConstants>
<NoWarn>;2008</NoWarn>
<NoStdLib>true</NoStdLib>
<DebugType>full</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
<OutputPath>bin\ARM64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UAP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<NoStdLib>true</NoStdLib>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
Expand Down Expand Up @@ -53,7 +77,6 @@
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
Expand All @@ -64,7 +87,6 @@
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
Expand Down Expand Up @@ -194,6 +216,9 @@
<Content Include="$(SharedContentDir)\media\smalltile-sdk.png">
<Link>Assets\smallTile-sdk.png</Link>
</Content>
<Content Include="$(SharedContentDir)\media\badge-logo.png">
<Link>Assets\badge-logo.png</Link>
</Content>
<Content Include="$(SharedContentDir)\media\splash-sdk.png">
<Link>Assets\splash-sdk.png</Link>
</Content>
Expand All @@ -218,12 +243,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.0.0</Version>
<Version>6.2.14</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
Expand All @@ -237,4 +257,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
12 changes: 12 additions & 0 deletions Samples/Geolocation/cs/Geolocation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM.ActiveCfg = Debug|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM.Build.0 = Debug|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM.Deploy.0 = Debug|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM64.Build.0 = Debug|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|ARM64.Deploy.0 = Debug|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|x64.ActiveCfg = Debug|x64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|x64.Build.0 = Debug|x64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Debug|x64.Deploy.0 = Debug|x64
Expand All @@ -29,6 +34,9 @@ Global
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM.ActiveCfg = Release|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM.Build.0 = Release|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM.Deploy.0 = Release|ARM
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM64.ActiveCfg = Release|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM64.Build.0 = Release|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|ARM64.Deploy.0 = Release|ARM64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|x64.ActiveCfg = Release|x64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|x64.Build.0 = Release|x64
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|x64.Deploy.0 = Release|x64
Expand All @@ -37,12 +45,16 @@ Global
{C214806D-57CA-5528-89FA-B9A7DEB22DFF}.Release|x86.Deploy.0 = Release|x86
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|ARM.ActiveCfg = Debug|ARM
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|ARM.Build.0 = Debug|ARM
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|ARM64.ActiveCfg = Debug|ARM64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|ARM64.Build.0 = Debug|ARM64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|x64.ActiveCfg = Debug|x64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|x64.Build.0 = Debug|x64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|x86.ActiveCfg = Debug|x86
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Debug|x86.Build.0 = Debug|x86
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|ARM.ActiveCfg = Release|ARM
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|ARM.Build.0 = Release|ARM
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|ARM64.ActiveCfg = Release|ARM64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|ARM64.Build.0 = Release|ARM64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|x64.ActiveCfg = Release|x64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|x64.Build.0 = Release|x64
{5A7BDE18-030E-5DC9-B9A2-70EA568A6E9D}.Release|x86.ActiveCfg = Release|x86
Expand Down
4 changes: 2 additions & 2 deletions Samples/Geolocation/cs/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Geolocation.App">
<uap:VisualElements DisplayName="Geolocation C# Sample" Square150x150Logo="Assets\SquareTile-sdk.png" Square44x44Logo="Assets\SmallTile-sdk.png" Description="Geolocation C# Sample" BackgroundColor="#00b2f0">
<uap:SplashScreen Image="Assets\Splash-sdk.png" />
<uap:LockScreen Notification="badge" BadgeLogo="Assets\smalltile-sdk.png" />
<uap:LockScreen Notification="badge" BadgeLogo="Assets\badge-logo.png" />
</uap:VisualElements>
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTask.GeofenceBackgroundTask">
Expand All @@ -41,4 +41,4 @@
<Capabilities>
<DeviceCapability Name="location" />
</Capabilities>
</Package>
</Package>
2 changes: 2 additions & 0 deletions Samples/Geolocation/cs/Scenario1_TrackPosition.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ private void UpdateLocationData(Geoposition position)
ScenarioOutput_Latitude.Text = "No data";
ScenarioOutput_Longitude.Text = "No data";
ScenarioOutput_Accuracy.Text = "No data";
ScenarioOutput_Source.Text = "No data";
ScenarioOutput_IsRemoteSource.Text = "No data";
}
else
{
ScenarioOutput_Latitude.Text = position.Coordinate.Point.Position.Latitude.ToString();
ScenarioOutput_Longitude.Text = position.Coordinate.Point.Position.Longitude.ToString();
ScenarioOutput_Accuracy.Text = position.Coordinate.Accuracy.ToString();
ScenarioOutput_Source.Text = position.Coordinate.PositionSource.ToString();
ScenarioOutput_IsRemoteSource.Text = position.Coordinate.IsRemoteSource.ToString();
}
}
Expand Down
Loading

0 comments on commit 0db108e

Please sign in to comment.