Android 安卓警报震动不工作
我创建了AlarmReceiver类,并在接收报警时添加了振动功能。在我的代码中,一定有一些错误,因为收到警报时振动不会启动。这是代码的一部分:Android 安卓警报震动不工作,android,vibration,Android,Vibration,我创建了AlarmReceiver类,并在接收报警时添加了振动功能。在我的代码中,一定有一些错误,因为收到警报时振动不会启动。这是代码的一部分: Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds } private Vibrator getSystemService(String vibrat
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
}
private Vibrator getSystemService(String vibratorService) {
// TODO Auto-generated method stub
return null;
}
}
当然,我在清单中添加了p
ermission
。我是否需要实现此代码的getSystemService
,如果我没有实现此方法,则eclipse
会抛出一个我需要实现此方法的错误。您不需要实现getSystemService。您需要对其进行caal以访问可控震源对象,然后在其上调用振动方法。
但是,您需要将getSystemService返回的对象强制转换为可控震源
Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500});