80
loading...
This website collects cookies to deliver better user experience
Vibration is a mechanical phenomenon whereby oscillations occur about an equilibrium point. The word comes from Latin vibrationem ("shaking, brandishing"). The oscillations may be periodic, such as the motion of a pendulum—or random, such as the movement of a tire on a gravel road. source: wikipedia.
shaking refers to move (an object) up and down or from side to side with rapid, forceful, jerky movements. source: google
<uses-permission android:name="android.permission.VIBRATE"/>
val vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
if (vibrator.hasVibrator()) {
// start vibration
}
else {
// device has no vibration feature
}
// vibrate 100 milliseconds and sleep 1000 milliseconds
// vibrate 200 milliseconds and sleep 2000 milliseconds
val vibrationPattern= longArrayOf(0, 100, 1000, 200, 2000)
// Start the vibration
vibrator.vibrate(vibrationPattern, -1) // does not repeat
vibrator.vibrate(vibrationPattern, 0) // repeats forever
dependencies {
// seismic
implementation 'com.squareup:seismic:1.0.2'
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
shakeDetector = ShakeDetector(ShakeDetector.Listener {
Toast.makeText(this, "Shake detected!", Toast.LENGTH_SHORT)
.show()
})
}
override fun onResume() {
super.onResume()
shakeDetector.start(sensorManager)
}
override fun onPause() {
super.onPause()
shakeDetector.stop()
}