Question

I want to implement:

I want to vibrate the phone for the specified minutes, I am getting the input using EditText and converting to millseconds by multiplying minutes with 60000 and then passing it as argument to vibrate(), it should vibrate for the specified millseconds, but its vibrating only for 15 seconds..

I have done code:

  Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  final EditText minutess = (EditText) findViewById(R.id.minutes);
                // to string
                String min = minutess.getText().toString();
                minutess.setVisibility(4);
                stopButton.setVisibility(1);
                try{
                long mins = Long.parseLong(min);
                long milis = mins*60000;
                startButton.setVisibility(4);
                v.vibrate(milis);
                }
       catch (NumberFormatException e) 
            { 
               //something else done here

            }

Even when the time in milliseconds is passed to vibrate() , it vibrating only for 15 seconds only. I am very much new to java and I want to know if theres anything wrong in the above code ..

Was it helpful?

Solution

It doesn't say in the docs, but 15 seconds may be a hardware-set limit on vibration time. You may want to test it out on a different device to see if it goes longer or shorter before stopping.

But if all devices can only vibrate for 15 seconds, you could split the desired time into 15 seconds chunks, restarting the vibration each time until it should stop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top