我正在制作简单的应用程序,它正在改变音量设置。
我希望在响铃或接收通知时实现切换振动。我使用的是AudioManager.setVibrateSetting(int vibrateType, int vibrateSetting)
,但在API级别16上已弃用此方法。
你知道其他任何方式,怎么做?
答案 0 :(得分:0)
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Start without a delay
// Vibrate for 100 milliseconds
// Sleep for 1000 milliseconds
long[] pattern = {0, 100, 1000};
// The '0' here means to repeat indefinitely ('-1' here means to vibrate once, as '-1' is out of bounds in the pattern array)
// '0' is actually the index at which the pattern keeps repeating from (the start)
// To repeat the pattern from any other point, you could increase the index, e.g. '1'
v.vibrate(pattern, 0);
请试一试。