Class

DeviceData


Description

Provides information about the mobile device such as battery level, orientation and more.

Enumerations

DeviceData.BatteryStates

BatteryStates

The possible charging states of the battery.

Enum

Description

Unknown

The current state of the battery cannot be determined.

Unplugged

The device is not plugged into a power source and the battery level is discharging.

Charging

The device is plugged into a power source but the battery is less than 100% charged.

Full

The device is plugged into a power source but the battery is 100% charged.

DeviceData.Orientations

Orientations

The positions a device can be in.

Enum

Description

Unknown

The orientation of the device cannot be determined.

Portrait

The device is perpendicular to the ground with the top of the device pointed upward.

PortraitUpsideDown

The device is perpendicular to the ground with the bottom of the device pointed upward.

LandscapeLeft

The device is perpendicular to the ground with the top of the device pointed to the left.

LandscapeRight

The device is perpendicular to the ground with the top of the device pointed to the right.

FaceUp

The device is parallel to the ground with the screen facing upward.

FaceDown

The device is parallel to the ground with the screen facing downward.

DeviceData.UserInterfaceTypes

UserInterfaceTypes

The various possible device types.

Enum

Description

Unspecified

The user interface type was not specified.

Phone

The user interface is that of a smartphone.

Tablet

The user interface is that of a tablet.

Property descriptions


DeviceData.BatteryLevel

BatteryLevel As Double

The amount of battery remaining.

This property is read-only.

A value of 0.0 means the battery is full discharged. A value of 1.0 means the battery is fully charged.

This example enables monitoring of the battery, gets the current battery level, disables battery monitoring and then displays the level in a message box:

System.Device.BatteryMonitoringEnabled = True
Var batteryPercentage As Integer = System.Device.BatteryLevel * 100
System.Device.BatteryMonitoringEnabled = False
MessageBox("Your battery is at " + batteryLevel.ToString + "%")

DeviceData.BatteryMonitoringEnabled

BatteryMonitoringEnabled As Boolean

If True, the BatteryLevel and BatteryState will be updated.

To preserve battery, set this property to True only while you need to have up to date battery information then set it back to False.

This example enables monitoring of the battery, gets the current battery level, disables battery monitoring and then displays the level in a message box:

System.Device.BatteryMonitoringEnabled = True
Var batteryPercentage As Integer = System.Device.BatteryLevel * 100
System.Device.BatteryMonitoringEnabled = False
MessageBox("Your battery is at " + batteryLevel.ToString + "%")

DeviceData.BatteryState

BatteryState As BatteryStates

Indicates if the battery is charging, fully charged, etc.

This property is read-only.

To get the current state of the battery, BatteryMonitoringEnabled must be True. One you no longer need to know the current battery state, set BatteryMonitoringEnabled to False.


DeviceData.Identifier

Identifier As String

A string of characters that uniquely identifies the device.

This property is read-only.


DeviceData.IsProximityNear

IsProximityNear As Boolean

If True, the device is near the user.

This property is read-only.

The ProximityMonitoringEnabled property must be True for this property to return accurate information. To preserver battery power, only set ProximityMonitoringEnabled to True while calling IsProximityNear and then set it to False as soon as you no longer need it.

If the device is near the user, display a message:

System.Device.ProximityMonitoringEnabled=True
If System.Device.IsProximityNear Then
  MessageBox("The device is close to you.")
End If
System.Device.ProximityMonitoringEnabled=False

DeviceData.IsRunningOnDevice

IsRunningOnDevice As Boolean

If True, the app is running on a physical device rather then in an emulator.

This property is read-only.

Important

This is supported for Android only.


DeviceData.LocalizedModel

LocalizedModel As String

The device model name localized for the language of the device.

This property is read-only.


DeviceData.Model

Model As String

The device model name.

This property is read-only.


DeviceData.Name

Name As String

The name of the device.

This property is read-only.

This is the name the user gave the device. On iOS, this name appears in Settings > General > About > Name.


DeviceData.Orientation

Orientation As Orientations

The orientation of the device.

This property is read-only.

This allows you to determine the orientation of the device relative to the Earth. See Orientations for all possible orientations. MobileScreen.OrientationChanged event will be called anytime the orientation changes which is a likely place to access the Orientation property. However, you can access it at any other time.

This example displays a message box if the device is face down:

If System.Device.Orientation = System.DeviceData.Orientations.FaceDown Then
  MessageBox("Why are you ignoring me?")
End If

DeviceData.ProximityMonitoringEnabled

ProximityMonitoringEnabled As Boolean

If True, the operating system will update the app to indicate if the device is near the user or not.

To conserve battery power, set this property to True only when you need to check to see if the device is near the user or not and then immediately set it to False so that the device stops using energy to deliver this data to your app.

If the device is near the user, display a message:

System.Device.ProximityMonitoringEnabled=True
If System.Device.IsProximityNear Then
  MessageBox("The device is close to you.")
End If
System.Device.ProximityMonitoringEnabled=False

DeviceData.UserInterfaceType

UserInterfaceType As UserInterfaceTypes

Indicates the type of user interface the device provides.

This property is read-only.

This property makes it easy to determine if the device is a smartphone or a tablet.

Notes

When checking both battery and proximity information, it's important to keep the duration of time in which the app is monitoring this data to a minimum as doing so uses more battery power than usual.

You can get the DeviceData by accessing the System.Device method. DeviceData exists in the System module, so to access its enumerations, use System.DeviceData.

Compatibility

Mobile projects on all supported mobile operating systems.

See also

Object parent class; System module