Mike Eason
Mike Eason

Reputation: 9713

Testing for an SDK in Universal Windows App

I am creating a universal windows application which will be used on both desktop, and mobile devices. The mobile devices will use vibration API.

//Vibrate the device
VibrationDevice.GetDefault().Vibrate(TimeSpan.FromMilliseconds(100));

I have added the necessary extension to the project to allow for this:

Project reference extensions

The Windows Mobile Extensions for the UWP will of course, not be present on desktop machines, therefore I need to conditionally test to check whether the SDK is available so I can execute the Vibrate method.

Essentially, if the app is running on the desktop, I do not want to execute the Vibrate method, otherwise I'll receive the exception:

An exception of type 'System.TypeLoadException' occurred in Encore.Scanner.UI.exe but was not handled in user code

Additional information: Requested Windows Runtime type 'Windows.Phone.Devices.Notification.VibrationDevice' is not registered.

Is there a way I can check whether the SDK is available? Something like this:

if (...windows mobile extension is present)
{
    //Vibrate the device.    
    VibrationDevice.GetDefault().Vibrate(TimeSpan.FromMilliseconds(100));
}

Upvotes: 2

Views: 402

Answers (1)

Mike Eason
Mike Eason

Reputation: 9713

I found what I needed. Here's how I achieved this if anyone stumbles across this problem in future.

if (ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice"))
{
    ...

Upvotes: 4

Related Questions