-1

I want the device to start vibrating for some amount of time when screen timeout option enables(when the light dims, before the screen shuts off).I know how to set up both functions individually, but I can't seem to manage to get them in the right order for this to work, so I need your help. Thanks and cheers!

1 Answers1

0

Use the vibrator class to initiate vibration

new Handler().postDelayed(new Runnable()
{
    @Override
    public void run()
    {
         Vibrator vib = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            // Vibrate for 500 milliseconds
            vib.vibrate(5);
     }
}, 30000); //30 sec 

Edit:

Don't forget as I did to declare in the app manifest file

<uses-permission android:name="android.permission.VIBRATE"/>
J.Vassallo
  • 2,282
  • 3
  • 15
  • 14