Android

vibrate



To let the smartphone vibrate, firstly the authority for that must be written on the AndroidManifest.xml:

<uses-permission android:name="android.permission.VIBRATE"/>


The vibration is activated with the following call:

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(400);  // vibrates for 400ms


It is also possible to carry out the vibration after a particular sample.
In the following example SOS is vibrated (3xshort, 3xlong, 3xshort):

pubilc static final int SHORTDOT  = 250;
public static final int LONGDOT   = 500;
public static final int SORTGAP   = 250;
public static final int LONGGAP   = 500;
long[] pattern = {
    0,  // Startet sofort
    SHORTDOT, SORTGAP, SHORTDOT, SORTGAP, SHORTDOT,    // s
    LONGGAP,
    LONGDOT, SORTGAP, LONGDOT, SORTGAP, LONGDOT,       // o
    LONGGAP,
    SHORTDOT, SORTGAP, SHORTDOT, SORTGAP, SHORTDOT,    // s
    LONGGAP
};
 
// carry out sample once (therefore -1):
v.vibrate(pattern, -1);


If you hand over a 0 at the gun, the vibrations occur endless and must be stopped by hand:

v.vibrate(pattern, 0);
.
.
v.cancel();  // stops vibration

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007