Mjafko Mjafko - 1 year ago 56
Android Question

Do action when vibration finish his pattern

Is there a way to do action specificly I want to set global boolean to true, when vibration finish his job ? Example of vibration function :

private void Vibration () {
if(vibrator.hasVibrator()) {
long ms[] = {0,50,60,50}; // 0 delay, vibrate(40 ms), sleep(60 ms), vibrate(40 ms)
vibrator.vibrate(ms,-1);
}
}

Answer Source

You can use TimerTask with schedule (TimerTask task,long delay) to trigger it when your vibration duration is over and do what you want to do when task is triggered

private void Vibration () {
        if(vibrator.hasVibrator()) {
            long ms[] = {0,50,60,50}; // 0 delay, vibrate(40 ms), sleep(60 ms), vibrate(40 ms)
            long delay = 0+50+60+50;
            vibrator.vibrate(ms,-1);
            Timer timerObj = new Timer();
            TimerTask timerTaskObj = new TimerTask() {
                public void run() {
                   //check =true;
                   // executed after the given delay 
                }
            };
            timerObj.schedule(timerTaskObj, delay);
        }
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download