Sdílet prostřednictvím


Context.DeviceId Property

Definition

Gets the device ID this context is associated with.

public virtual int DeviceId { [Android.Runtime.Register("getDeviceId", "()I", "GetGetDeviceIdHandler", ApiSince=34)] get; }
[<get: Android.Runtime.Register("getDeviceId", "()I", "GetGetDeviceIdHandler", ApiSince=34)>]
member this.DeviceId : int

Property Value

the ID of the device this context is associated with.

Attributes

Remarks

Gets the device ID this context is associated with. Applications can use this method to determine whether they are running on a virtual device and identify that device.

The device ID of the host device is Context#DEVICE_ID_DEFAULT

If the underlying device ID is changed by the system, for example, when an Activity is moved to a different virtual device, applications can register to listen to changes by calling Context#registerDeviceIdChangeListener(Executor, IntConsumer).

This method will only return a reliable value for this instance if it was created with Context#createDeviceContext(int), or if this instance is a UI or Display Context. Contexts created with Context#createDeviceContext(int) will have an explicit device association, which will never change, even if the underlying device is closed or is removed. UI Contexts and Display Contexts are already associated with a display, so if the device association is not explicitly given, Context#getDeviceId() will return the ID of the device associated with the associated display. The system can assign an arbitrary device id value for Contexts not logically associated with a device.

Java documentation for android.content.Context.getDeviceId().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to