#Hololens – Some APIs will work, other no, and there is no easy way to find it :S

Hello!

It is time to begin to share some experiences developing for Hololens. This post is related to UWP Apps, general base for all devices in Windows 10 family.

While have a base common of features in all the devices, for some features is a good practice to validate if the functionalities are implemented or not in each type of device.

As well, according to the article [Dynamically detecting features with API contracts (10 by 10)], the right way to do this is using the ApiInformation class. The example shared bu the Windows Dev Center team is very easy to read and understand:

using Windows.Foundation.Metadata;

if (ApiInformation.IsTypePresent(“Windows.Media.Playlists.Playlist”))
{
await myAwesomePlaylist.SaveAsAsync( … );
}

The code is self explanatory, if we can use the APIs of Playlist, we have everything ready to go on. In the Hololens scenario, this works very well. Some features like Print or Share, that are not directly available on the platform.
However, we must be careful here. In example: What happens if we want to access the camera from the Hololens and use the CameraCaptureUI class? This class we have an option to see in time real the feed of the camera and take a photo on this.

Note: I know is an inconsistency to use this in the Hololens. Camera will always show what they are seeing. However as an example for the post it comes great!

So, if we use CameraCaptureUI we’ll have the following steps in Hololens:

  • The API CameraCaptureUI will be returned as available in Hololens
  • When we use it, Windows 10 will suggests us to download an app from the Store for this
  • What?

Here is a live sample:

2016 08 23 Hololens CameraCaptureUi

Using this sample code:

Clipboard02

So, for this scenario, validate the availability of an API is not working. Here comes the time of go for an ungly solution

Use AnalyticsInfo.VersionInfo.DeviceFamily to see the type of device where the app is running. In the case of the Hololens this property returns “Windows.Holographic”.

This solution works. And I know, I add a BIG NOTE: As soon as UWP has a better way to validate this type of scenarios, this feature and evidence must be eliminated!

Clipboard06

A kitten and 2 unicorns less thanks to 5 lines of code! Sorry about that 😦

Greetings @ Toronto

El Bruno

References

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.