我的 android 应用程序中有一个 BroadcastReceiver。当我的接收器发生特殊情况时,我想振动。
我知道如何控制振动,但有两个问题:
1-当按下电源按钮并且屏幕关闭时,设备停止振动。2-再次打开屏幕后,如果我的振动重复参数设置为大于 1,它就不再振动。
这是我的振动方法:
public void startVibrate(Context context, int repeat) {
vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
int dot = 200; // Length of a Morse Code "dot" in milliseconds
int dash = 500; // Length of a Morse Code "dash" in milliseconds
int short_gap = 200; // Length of Gap Between dots/dashes
int medium_gap = 500; // Length of Gap Between Letters
int long_gap = 1000; // Length of Gap Between Words
long[] pattern = {
0, // Start immediately
dot, short_gap, dot, short_gap, dot, medium_gap, // S
dash, short_gap, dash, short_gap, dash, medium_gap, // O
dot, short_gap, dot, short_gap, dot, long_gap // S
};
vibrator.vibrate(pattern, repeat);
//vibrator.vibrate(10000);
}
这是振动方法调用:
controller.startVibrate(context, 0);