import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.*; import java.util.regex.*; import java.util.*; import android.app.Activity; import android.widget.*; import android.graphics.*; import android.hardware.Camera; import android.view.*; public class main { static Activity androidContext; public static void main(String[] args) throws Exception { System.out.println("Listing cameras..."); androidContext.runOnUiThread(new Runnable() { public void run() { try { int n = Camera.getNumberOfCameras(); System.out.println("Cameras: " + n); //final Camera cam = Camera.open(0/*n-1*/); TextureView mTextureView = new TextureView(androidContext); mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { Camera mCamera; public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mCamera = Camera.open(0); try { mCamera.setPreviewTexture(surface); mCamera.startPreview(); } catch (IOException ioe) { // Something bad happened } } public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Ignored, Camera does all the work for us } public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { mCamera.stopPreview(); mCamera.release(); return true; } public void onSurfaceTextureUpdated(SurfaceTexture surface) { // Invoked every time there's a new Camera preview frame } }); androidContext.setContentView(mTextureView); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); } static class CamCallback implements SurfaceHolder.Callback { public void surfaceChanged (SurfaceHolder holder, int format, int width, int height) { System.out.println("surfaceChanged"); } public void surfaceCreated (SurfaceHolder holder) { System.out.println("surfaceCreated"); } public void surfaceDestroyed (SurfaceHolder holder) { System.out.println("surfaceDestroyed"); } } static class ShutterCallback implements Camera.ShutterCallback { public void onShutter() { System.out.println("Shutter!"); } } static class JpegCallback implements Camera.PictureCallback { public void onPictureTaken (byte[] data, Camera cam) { TextView tv = new TextView(androidContext); tv.setText("Picture data: " + data.length); androidContext.setContentView(tv); System.out.println("Picture data: " + data.length); cam.release(); System.out.println("Camera released."); } } }