문제

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);
    }
}

While using the Broadcast Receiver to vibrate the device when using an Alarm, there's an error as shown above . What may be the possible reason for an error here ?

도움이 되었습니까?

해결책

Try this

Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(3000);

다른 팁

did you give permission?

   <uses-permission android:name="android.permission.VIBRATE"></uses-permission> 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top