title: How to make an Android app to vibrate phone indefinitely?
body: <p>I want to make an Android app to make a phone vibrate indefinitely. I tried the approach recommended in different other threads but it does not seem to work. The phone vibrates, but after a moment it stops for a small fraction of second before restarting. And the pattern repeats itself every ~1 second. It does not matter the value I put in <code>patternT</code>, the behavior is always the same. Is it possible to make the phone vibrate indefinitely (without any lag or stop) ? The phone used is a Google Pixel 4 on Android 11.</p>
  <p>Here is my code :</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private void vibrate() {
          long[] patternT = new long[]{0, 50};
          int[] patternA = new int[]{0, VibrationEffect.DEFAULT_AMPLITUDE};
          VibrationEffect ve = VibrationEffect.createWaveform(patternT, patternA, 0);
          Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
          v.vibrate(ve);
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final Button vibrateBtn = findViewById(R.id.btnVibrate);
          vibrateBtn.setOnClickListener(view-&gt;vibrate());
      }
  }
  </code></pre>