2
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 ?

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
Chetna
  • 165
  • 1
  • 6
  • 15
  • 1
    What's the error? Maybe you forgot to add the permission in the manifest. – iamtheexp01 Jun 04 '12 at 07:21
  • Its a syntax error that a ';' is missing but it isn't. and regarding the permission, yes i have added that. – Chetna Jun 04 '12 at 07:29
  • @iamthe.exception your question made me solve this issue: [link](http://stackoverflow.com/questions/11939164/change-output-volume-in-broadcastreceiver-for-notification-for-non-streaming-pre) – Eugene van der Merwe Aug 13 '12 at 17:38

2 Answers2

2

Try this

Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(3000);
swathi
  • 673
  • 1
  • 5
  • 7
  • This looks better - the vibrator variable wasn't being initialised. I'd have thought you'd be getting a NullPointerException... – barry Jun 04 '12 at 08:09
0

did you give permission?

   <uses-permission android:name="android.permission.VIBRATE"></uses-permission> 
Botz3000
  • 39,020
  • 8
  • 103
  • 127
Prachi
  • 2,559
  • 4
  • 25
  • 37