我用振动服务在Android和设置时间= 500毫秒,如下为什么我的应用程序不断震动?
Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
long milliseconds = 500;
v.vibrate(milliseconds);
有时它的工作确定,但有时我不知道为什么它不断地振动,只有当我打开屏幕停止。 我的应用程序适用于Android 2.2。
请帮帮我。
非常感谢。
/**编辑*/
感谢您的答复,
我开始报警服务内部振动。每当警报响起时,我会播放声音,启动这个服务中的振动。这里是我的代码
Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
long milliseconds = 500;
v.vibrate(milliseconds);
MediaPlayer mp = MediaPlayer.create(this, R.raw.normal);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
PowerManager pm = (PowerManager) this
.getSystemService(Context.POWER_SERVICE);
mWakelock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "AlarmScreen");
mWakelock.acquire(120000);
的问题是,有时它工作正常,但有时它不断地振动,只有当我打开屏幕停止。
“这个”这里是我们的服务对象本身停止振动。我不认为这是我的问题。 – MichaelP 2012-02-10 09:53:22
尝试mp.start前mp.release()()每次调用媒体播放器... – timonvlad 2012-02-10 13:22:52
感谢您的时间,但我得到异常IllegalStateException异常时,我打电话mp.start(前mp.release()) – MichaelP 2012-02-13 02:20:33