Hi I want to call a vibration class throughout my android activities. Can someone please point me in the right direction? This is my vib class so far:
import android.content.Context;
import android.os.Vibrator;
public class Vibrate {
Vibrator vibs = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void vib(int length) {
vibs.vibrate(length);
}
}
and I want to call this guy from one of my activities like this:
Vibrate vib = new Vibrate();
...
vib.vib(500);
Thanks for all your help!
Something like this:
public class Vibrate {
private Context mContext;
private Vibrator mVibrator;
public Vibrate(Context context) {
mContext = context;
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
}
public void vib(int length) {
mVibrator.vibrate(length);
}
}
Vibrate vib = new Vibrate(this);
But I don't know why do you need such a class if Vibrator
should be enough.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.