This post is Day #12 in a series called the 31 Days of Windows Phone.
Yesterday, we talked about the accelerometer on Windows Phone, and how we can pretend to have a real device giving us data. Today, we’re going to talk about the VibrateController, and how we can give feedback to our users about what is happening with our application.
Because telling someone how to make their phone vibrate immediately evokes tasteless jokes, I’ll let you get them out of your system here, before I have to write “vibration” 15 more times. Go ahead…I’ll wait.
Why Make the Phone Vibrate?
There’s certainly a great number of silly and/or inappropriate reasons to make a phone vibrate. For the purposes of this article, however, I’m going to cover some of the specific reasons you’d make the phone vibrate.
Let’s start with the obvious one: games. When you’re playing a game, you might not always be able to give the user all of the information they need on-screen. (Especially when they’ve got their fingers on the screen.) Giving them “haptic feedback” allows them to know they’re being attacked, or that they need to pay more attention to something important.
This is probably going to be far more common for you, but for every button you have on your application, haptic feedback lets the user know they pressed the button appropriately. Default buttons in Windows Phone turn a solid color when pressed, but many times users aren’t certain they made the click (especially if the action takes a few seconds to happen.) Giving them a quick vibration lets them know they accomplished their goal.
Another obvious, but underused opportunity for vibration feedback is notifications. By default, if you get an email, text message, etc., your phone vibrates (or makes a noise). We should leverage that same user experience in our applications. When the user should be alerted to something, make the phone vibrate. This is especially important when your application is a passive one. For example, an application that tracks your location as you run through your neighborhood. If it loses a signal, or perhaps you reach your target distance, a vibration would let the user know, without looking at their phone. In that same example, you could even give them feedback each 1/4 mile, so that they’re aware of how far they’ve gone.
How Do I Make the Phone Vibrate?
Thankfully, this is incredibly simple. You need two lines of code to make it happen, but you should spend a significant amount of time tweaking this to your specific needs. Here’s the basic code:
VibrateController vc = VibrateController.Default; vc.Start(TimeSpan.FromMilliseconds(100));
How long should I make it vibrate?
There aren’t any specific rules about how long vibration should happen for a specific notification, but I have some guidelines I follow, and I’ll share them with you:
- 1/10 of a second is the appropriate amount of time for a button press. (It’s also the shortest amount of time the VibrateController can vibrate).
- 2 seconds = “WHAT IS WRONG WITH MY PHONE?!??!?” to your users. 2 seconds is WAY too long for any single notification.
- 300 milliseconds (~1/3 of a second) seems to be a good amount of time for one steady notification vibration. It gets your user’s attention without making them think that something is wrong with their phone.
- Quick pulses of vibration are another great way to let the user know what is happening. I have included this example in my sample code download below, but for a clearer explanation for how I’m doing it, check out my tutorial on “How To Create A SetTimeout Function In Silverlight.”
Download the Code
We’ve got some heavy-duty topics coming up in the next few days, including Location Services and Tombstoning. Please leave a comment on any of the posts in this series to let me know what you think!