Pergunta

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 ?

Foi útil?

Solução

Try this

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

Outras dicas

did you give permission?

   <uses-permission android:name="android.permission.VIBRATE"></uses-permission> 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top