Android vibrator service error
-
04-06-2021 - |
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);
}
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