Introduction
In this article we will learn how to vibrate the Phone. Vibration Can be used to alert the user for any kind of Notification. In games it can also be used.
Open visual studio and create a Blank Project
Step 1: First add two button in MainPage.xaml in Content pannel grid, one to start the vibration and the second to stop vibration.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button x:Name="startVibrate" Margin="20,0,0,0" Height="80" Click="Vibratestart_Clicked" Content="Start Vibrate" />
<Button x:Name="stopVibrate" Margin="20,200,0,0" Height="80" Click="Vibratestop_Clicked" Content="Stop Vibrate" />
</Grid>
Step 2: In constructor of MainPage.xaml.cs Add the vibrate controller class.
VibrateController vibrate = VibrateController.Default;
Step 3: Add startVibrate_Clicked and stopVibrate_Clicked event to start and stop the vibration respectively.
private void Vibratestart_Clicked(object sender, RoutedEventArgs e)
{
vibrate.Start(TimeSpan.FromMilliseconds(5000));
//5000 =5 seconds
}
You can change the vibration time
private void Vibratestop_Clicked(object sender, RoutedEventArgs e)
{
vibrate.Stop();
}
Note: Vibration can be tested only on the device not on emulator.
Now run the Application on a DEVICE .
Click Here to download Sample Project

No comments:
Post a Comment