Android examples for android.media:Microphone
Check if Microphone is Available by recording something
import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.media.MediaRecorder; import android.speech.RecognizerIntent; import java.io.File; import java.io.IOException; import java.util.List; public class Main{ public static boolean isMicrophoneAvailable(Context context) { MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); recorder.setOutputFile(new File(context.getCacheDir(), "MediaUtil#micAvailTestFile").getAbsolutePath()); boolean available = true; try {/* w w w.j a v a 2 s .c o m*/ recorder.prepare(); } catch (IOException exception) { available = false; } recorder.release(); return available; } }