Android examples for Media:Audio
Create Beep sound
//package com.java2s; import android.content.Context; import android.media.AudioManager; import android.media.ToneGenerator; import android.os.Handler; import android.os.Vibrator; public class Main { public static void soundButton(Context context) { final ToneGenerator toneGenerator = new ToneGenerator( AudioManager.STREAM_SYSTEM, ToneGenerator.MAX_VOLUME); toneGenerator.startTone(ToneGenerator.TONE_PROP_BEEP); Handler hundler = new Handler(); hundler.postDelayed(new Runnable() { @Override/* w w w. java 2s. c o m*/ public void run() { toneGenerator.stopTone(); } }, 1000); vibrator(context, 100); } public static void vibrator(Context context, int msec) { Vibrator vib = (Vibrator) context .getSystemService(Context.VIBRATOR_SERVICE); if (vib != null) { vib.vibrate(msec); } } }