我试图在片段中使用振动,但我在上下文中遇到错误。我如何在片段中使用它?谢谢,这是我的代码:
Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
答案 0 :(得分:2)
试试此代码
Vibrator v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
或
Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);