import javax.imageio.*; import java.awt.image.*; import java.awt.event.*; import java.awt.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.text.*; import javax.swing.*; import java.util.concurrent.*; import java.util.regex.*; import java.util.List; import java.util.zip.*; import java.util.*; import android.media.*; public class main { static Object androidContext; public static void main(String[] args) throws Exception { print("Making MediaRecorder."); String outputPath = "/storage/sdcard0/JavaX-Record/bla.3gpp"; mkdirsForFile(new File(outputPath)); print("Recording to: " + outputPath); MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(outputPath); recorder.prepare(); recorder.start(); // Recording is now started print("Recording."); sleep(5000); recorder.stop(); print("Stopped recording."); recorder.reset(); // You can reuse the object by going back to setAudioSource() step recorder.release(); long len = new File(outputPath).length(); print("File size: " + len); } public static void mkdirsForFile(File file) { File dir = file.getParentFile(); if (dir != null) // is null if file is in current dir dir.mkdirs(); } static void sleep(long ms) { try { Thread.sleep(ms); } catch (Exception e) { throw new RuntimeException(e); } } static void sleep() { try { synchronized(main.class) { main.class.wait(); } } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} static void print() { System.out.println(); } static void print(Object o) { System.out.println(o); } static void print(long i) { System.out.println(i); } }