public class MyBroadcastReceiver extends BroadcastReceiver{
public void onReceive(Context context , Intent intent){
Toast.makeText(context, "Your time is up", Toast.LENGTH_LONG).show();
Vibrator vibrator;
// ERROR here (vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
}
}
在使用闹钟时使用广播接收器振动设备时,会出现如上所示的错误。这里可能出现错误的原因是什么?
答案 0 :(得分:2)
试试这个
Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(3000);
答案 1 :(得分:0)
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>