How to display a device icon (HTML)

This topic shows you how to display a device icon.

What you need to know


  • Windows Runtime


  • You should be familiar with HTML and JavaScript.


Step 1: Open Microsoft Visual Studio

Open an instance of Microsoft Visual Studio.

Step 2: Create a new project

In the New Project dialog box, from the JavaScript > Windows Store apps project types, click Blank Application.

Step 3: Insert the HTML

Open Default.html and replace the contents of the file with this code.

<!DOCTYPE html>
    <title>Display the Device Icon</title>
    <script type="text/javascript" src="/js/default.js"> </script>

    <h1>Device Icon</h1>

    <div id="statusMessage"></div>
    // The size of the returned icon is 256 X 256.
    <img id="deviceImage"/>


Step 4: Insert a function for displaying an icon

Open Default.js, and replace the contents with the following code.

// Takes a parameter of type DeviceInformation
// and retrieves a DeviceThumbnail to pass to displayImage().
function getImage (device) {   

    var thumbnail = null;
    if (device){
            function (thumbnail) {
            // A valid thumbnail is always returned.

function displayImage(imageFile) {
    try {
        // Setting 2nd parameter to 'false' cleans up 
        // the URL after first use.
        // We set this because we only need to load the URL
        // into the image tag once.
        document.getElementById("deviceImage").src = 
            window.URL.createObjectURL(imageFile, false);
    } catch (e) {
        document.getElementById("statusMessage").innerHTML = 
            "Could not display image, error: " + e.message;

Note  Alternatively you can substitute the call to getThumbnailAsync with a call to getGlyphThumbnailAsync, to get a glyph for the device.


Step 5: Add code to enumerate a device

  1. Add code to your Default.js file that enumerates the device you want to display the icon for.
  2. Pass the DeviceInformation object for the device to the getImage() function that you defined.

The available devices with icons to display will depend on your system. This code finds the first camera, if one is available, and displays the image for it.

(function() {
    var Enum = Windows.Devices.Enumeration;

function successCallback(deviceInformationCollection) {
    var numDevices = deviceInformationCollection.length;
    if (numDevices) {
    } else {
        document.getElementById("statusMessage").innerHTML =
            "No devices found.";


The size of the returned icon is 256 x 256 pixels.

Use getThumbnailAsync to get a photorealistic icon for the device. Use getGlyphThumbnailAsync to get a glyph for the device.