# Android 移动端脚本

> Contains information about scripting for Android.

对于跨平台项目，请使用 `UNITY_ANDROID` 定义指令来条件编译 Android 特定的 C# 代码。有关更多信息，请参阅有关[平台依赖编译 (Platform-dependent compilation)](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/platform-dependent-compilation.md) 的文档。

## 访问设备特有的功能和属性##access-device-specific-features-and-properties

应用程序可以通过 [Input](/engine/6000.0/script-reference/unity-engine/input.md) 和 [Handheld](/engine/6000.0/script-reference/unity-engine/handheld.md) 类访问 Android 设备的大多数功能。有关更多信息，请参阅：

* [移动设备输入](/engine/6000.0/manual/working-in-unity/input/legacy/mobile.md)
* [移动键盘](/engine/6000.0/manual/working-in-unity/input/mobile-keyboard.md)

### 振动支持##vibration-support

要触发振动，请在代码中调用 [Handheld.Vibrate](/engine/6000.0/script-reference/unity-engine/handheld/vibrate.md)。不含振动硬件的设备将忽略此调用。

### 活动指示器##activity-indicator

移动操作系统内置了活动指示器，应用程序可以在执行缓慢操作时使用这些指示器。有关更多信息，请参阅 [Handheld.StartActivityIndicator](/engine/6000.0/script-reference/unity-engine/handheld/start-activity-indicator.md)。

要访问设备特有的属性，请使用以下 API：

| **Script**                                                                                                                | **设备属性**                                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [SystemInfo.deviceUniqueIdentifier](/engine/6000.0/script-reference/unity-engine/system-info/device-unique-identifier.md) | 始终返回 `ANDROID_ID` 的 MD5。有关更多信息，请参阅 Android 开发者文档中的 [ANDROID\_ID](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID) 部分。 |
| [SystemInfo.deviceName](/engine/6000.0/script-reference/unity-engine/system-info/device-name.md)                          | 返回设备名称。对于 Android 设备，Unity 会尝试从安全系统设置中读取 `device_name` 和 `bluetooth_name`。如果这些字符串没有值，Unity 将返回 `<unknown>`。                                                    |
| [SystemInfo.deviceModel](/engine/6000.0/script-reference/unity-engine/system-info/device-model.md)                        | 返回设备型号。这通常包括制造商名称和型号（例如“LGE Nexus 5”或“SAMSUNG-SM-G900A”）。                                                                                                      |
| [SystemInfo.operatingSystem](/engine/6000.0/script-reference/unity-engine/system-info/operating-system.md)                | 返回操作系统名称和版本。                                                                                                                                                   |
