Pergunta

Does anyone know why my vibrate service is having an error when I click the Buttons? It says "....... force close". Here's my code:

final Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

public void onClick(View v) {
    Intent newgameIntent = new Intent(BodyPartsGameActivity.this,gamelevel.class);
    startActivity(newgameIntent);
    mp.start();
    mVibrator.vibrate(500);
}
Foi útil?

Solução

You must specify the permission to use the vibrator. Otherwise the security framework will shut down your application.

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