有没有办法在它们之间进行300ms的说明?
我有一个问题:我应该以500ms *,300ms的暂停,500ms *的振动,300ms的暂停和最后500毫秒 *的振动来振动手机。我尝试使用处理程序,但不幸的是,就像他们在一个等待时间内加起来一样。是否有一种特定的方法可以顺序进行所有这些操作,并通过它们之间的延迟进行延迟?一千个感谢。
时间因许多因素而异
val vibration = requireActivity().getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration1.toLong())
}, 600)
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration2.toLong())
}, 2000)
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration3.toLong())
id.setImageDrawable(AppCompatResources.getDrawable(requireActivity(), R.drawable.ic_play))
}, 3600)
I have this problem: I should vibrate the phone for 500ms *, 300ms of pause, 500ms * of vibration, 300ms of pause and finally 500ms * of vibration. I tried using Handler but unfortunately it's like they add up in one wait time. Is there a specific way to do all these operations sequentially and by putting a delay between them? A thousand thanks.
Time varies depending on many factors
val vibration = requireActivity().getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration1.toLong())
}, 600)
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration2.toLong())
}, 2000)
Handler(Looper.getMainLooper()).postDelayed({
vibration.vibrate(code.code.duration3.toLong())
id.setImageDrawable(AppCompatResources.getDrawable(requireActivity(), R.drawable.ic_play))
}, 3600)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下代码,这对我来说非常有用。
在上面的代码中,您会看到,
Try the below code, which is working for me perfectly.
In the above code, you will see that,
您可以使用更可读的Coroutine,而不是使用处理程序或线程。
Instead of using Handlers or Threads, you can use a coroutine which would be more readable.