Share via


VibrationDevice 类

定义

振动手机。

public ref class VibrationDevice sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Phone.PhoneContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class VibrationDevice final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Phone.PhoneContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class VibrationDevice
Public NotInheritable Class VibrationDevice
继承
Object Platform::Object IInspectable VibrationDevice
属性

Windows 要求

设备系列
Windows Mobile Extension SDK (在 10.0.10240.0 中引入)
API contract
Windows.Phone.PhoneContract (在 v1.0 中引入)

示例

通过调用 VibrationDevice 类的 Vibratione 方法振动手机。

  1. 导入 Windows.Phone.Devices.Notification 命名空间。

using Windows.Phone.Devices.Notification;

  1. 通过调用 VibrationDevice 类的静态 GetDefault 方法获取对振动控制器的引用。

VibrationDevice testVibrationDevice = VibrationDevice.GetDefault();

  1. 通过调用 VibrationDevice 类的 Vibratione 方法启动振动。 将持续时间指定为 TimeSpan 值。

testVibrationDevice.Vibrate(TimeSpan.FromSeconds(3));

  1. 如有必要,通过调用 VibrationDevice 类的 Cancel 方法停止振动。

testVibrationDevice.Cancel();

注解

Windows Phone设备包括振动控制器。 你的应用可将手机振动长达 5 秒,以通知用户发生重要事件。

在审查中使用振动功能。 不要依赖振动功能来获取关键通知,因为用户可以禁用振动。

若要测试有效使用振动控制器的应用,必须在物理设备上对其进行测试。 模拟器无法模拟振动,并且不提供发生振动的任何声音或视觉反馈。

在后台运行的应用无法振动手机。 如果代码尝试在应用在后台运行时使用振动,则不会发生任何异常,但不会引发异常。 如果要在应用在后台运行时振动手机,则必须实现 Toast 通知。

方法

Cancel()

停止手机的振动。

GetDefault()

获取 VibrationDevice 类的实例。

Vibrate(TimeSpan)

将手机振动指定持续时间 (0 到 5 秒) 。

适用于