Freigeben über


How to make your Windows Phone app vibrate?

There are 2 simple ways to make your Windows Phone app vibrate the device.

The first method makes use of the VibrateController class in the Microsoft.Devices namespace:

            VibrateController vibrateController = VibrateController.Default;
            vibrateController.Start(TimeSpan.FromSeconds(2));
            vibrateController.Stop();

The second method makes use of the VibrationDevice class in the Windows.Phone.Devices.Notification namespace:

 

            VibrationDevice vibrationDevice = VibrationDevice.GetDefault();

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

            vibrationDevice.Cancel();

In both these instances, the vibration will automatically stop after the amount passed as TimeSpan has elapsed.

You can call the corresponding Stop or Cancel method of the class to stop the vibration before the TimeSpan passed has elapsed.

Regards,
Paras Wadehra

Microsoft MVP

Twitter: @ParasWadehra

FB.com/WindowsPhoneDeveloper

My WP Apps

 

Via Blogspot

Comments

  • Anonymous
    January 02, 2015
    Please give some idea for windows phone 8.1 and windows store app .   Because namespaces for WP8.1 is completely changed.