1.最简单的方式
// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 400 milliseconds v.vibrate(400);
2.vibrate(long[] pattern, int repeat)
method:
// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Start without a delay // Vibrate for 100 milliseconds // Sleep for 1000 milliseconds long[] pattern = {0, 100, 1000}; // The '0' here means to repeat indefinitely // '0' is actually the index at which the pattern keeps repeating from (the start) // To repeat the pattern from any other point, you could increase the index, e.g. '1' v.vibrate(pattern, 0);
3.取消v.cancel(); 4.最后 <pre name="code" class="html"><uses-permission android:name="android.permission.VIBRATE"/>
5.// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Start without a delay // Each element then alternates between vibrate, sleep, vibrate, sleep... long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100}; // The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array v.vibrate(pattern, -1);
ps:private long pattern [] = {0,1000,1000,1000,1000,1000,1000};
震动没有延时,休眠一秒再震动一秒,重复三次。
节选自:http://stackoverflow.com/questions/13950338/how-to-make-an-android-device-vibrate
android 使手机震动的方法
最新推荐文章于 2023-09-22 17:16:35 发布