Alex VII
Alex VII

Reputation: 930

Problems with ACTION_TIME_TICK in Android

My Phone doesn't vibrate every minute. Here is my code:

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.os.Vibrator;

public class vibrateNow extends Service {
static IntentFilter s_intentFilter;
static {
    s_intentFilter = new IntentFilter();
    s_intentFilter.addAction(Intent.ACTION_TIME_TICK);
}
BroadcastReceiver yourReceiver;

public void onCreate() {
    super.onCreate();

    this.yourReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {
            showSuccessfulBroadcast();
        }
    };
    // Registers the receiver so that your service will listen for broadcasts
    vibrateNow.this.registerReceiver(vibrateNow.this.yourReceiver, s_intentFilter);
}

@Override
public IBinder onBind(Intent arg0) {
    return null;
}   

private void showSuccessfulBroadcast() {
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    // Vibrate for 300 milliseconds
    v.vibrate(300);

}
}

By the way in the way: I registered in Android Manifest the android.permission.VIBRATE permission.

Upvotes: 0

Views: 2067

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

You may have the permission in the wrong place.

Or, you may not be starting the service.

Or, you are starting the service, but are stopping it, and Android is getting rid of your empty process before the next tick arrives.

Or, you are testing on the emulator, which does not have a vibration motor.

Or, you are testing on a device that does not have a vibration motor.

There may be other problems, but those should get you started.

Upvotes: 1

Related Questions