vibrate

Android Vibrator手机震动详解

╄→尐↘猪︶ㄣ 提交于 2019-11-26 16:57:00
添加权限 在AndroidManifest.xml文件中添加如下震动权限 <uses-permission android:name="android.permission.VIBRATE"/> 获取Vibrator vibrator = (Vibrator)context.getSystemService(this.VIBRATOR_SERVICE); 简单震动 先看下简单震动方法vibrate(long milliseconds)的源码 /** * Vibrate constantly for the specified period of time. * * @param milliseconds The number of milliseconds to vibrate. * * @deprecated Use {@link #vibrate(VibrationEffect)} instead. */ @Deprecated @RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(long milliseconds) { vibrate(milliseconds, null); } 使用方法很简单,就是传入一个毫秒值,手机会持续震动该毫秒值时长,震动完即停止 vibrator