アプリケーションを 3 秒間振動させたいのですが、動作せず、理由がわかりません。ボタンをクリックしても何もしません。最初はメインアクティビティでやろうとしましたが、同じ結果でした。
主な活動
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final Button vibrateButton = new Button(this);
final Intent vibration = new Intent(this, MyService.class);
vibrateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(vibration);
}
});
}
サービス
public class MyService extends IntentService {
public MyService()
{
super("MyService");
}
@Override
protected void onHandleIntent(Intent vibration)
{
Vibrator vibe = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(3000);
}
}