object.androidDeviceId

类型 数字
对象 输入设备
修订版 发行版 2024.3703
关键词 设备、输入、androidDeviceId

概览

安卓为输入设备分配的唯一整数 ID。

请注意,安卓设备重启后,分配给输入设备的 ID 可能会发生变化。这意味着你切勿将该 ID 保存到文件中,并且只能在应用程序存在期间使用它。如果你需要在重启后保持不变的 ID,那么你应该考虑改用 permanentId 标识符,如果可用的话。

如果出现以下情况,将返回 nil

示例

-- Called when a key event has been received.
local function onKeyEvent( event )
    -- Print the device's unique Android ID, if available.
    -- Note: The "device" property will be nil if the platform does not support input devices
    --       or if input came from software, such as a virtual keyboard.
    if event.device then
        print( "Android Device ID: " .. tostring( event.device.androidDeviceId ) )
    end
end

-- Set up the above function to receive key events.
Runtime:addEventListener( "key", onKeyEvent )