List of usage examples for android.hardware Camera open
public static Camera open()
From source file:com.droid.app.fotobot.FotoBot.java
/** * ? , ?, ?/* www .j a v a 2s . co m*/ * * @param h * @param delay */ public void fbpause(final Handler h, final int delay) { if (delay > 3) { SendMessage(".", MSG_INFO); } PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); wakeLock.acquire(); Thread thread = new Thread() { public void run() { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); wakeLock.acquire(); int n = 5; if (delay >= wake_up_interval) { n = (int) (delay - ((delay / wake_up_interval) * long_pause * 2)); } for (int i = 1; i <= n; i++) { if (i % 3 == 0) { if (isCharging_before != isCharging) { if (isCharging) { SendMessage(getResources().getString(R.string.voltage_restored)); if (isCharging_sms) sendSMS(sms_voltage_alert_number, getResources().getString(R.string.voltage_restored)); } else { SendMessage(getResources().getString(R.string.no_voltage)); if (isCharging_sms) sendSMS(sms_voltage_alert_number, getResources().getString(R.string.no_voltage)); } isCharging_before = isCharging; } } Message msg = Message.obtain(); // Creates an new Message instance // we make 1 sec for each n try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } if (getstatus() == 3) { return; } if (i % 5 == 0 && sms_check_file) { // checking for sms file each 5 seconds during big pause between photos File sms_file = null; // sms_file = new File((getApplicationContext().getFilesDir().toString() + "/sms.txt")); sms_file = new File(work_dir + "/sms.txt"); if (sms_file.isFile()) { sms = file2array(sms_file.toString()); sms_getdata(); try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } for (int ind = 0; ind < sms.size(); ind++) { SendMessage(sms.get(ind).toString(), MSG_INFO); } SendMessage("SMS:", MSG_INFO); sms_file.delete(); sms.clear(); sms_update_db = true; if (sms_status && sms_incoming_passwd.equals(sms_passwd)) { sendSMS(sms_sender_num, "Bat: " + battery_level + "%\n" + "Upd: " + Photo_Frequency + "sec\n" + "Flash: " + Use_Flash + "\n" + "Net: " + network); sms_status = false; } if (sms_net_status && sms_incoming_passwd.equals(sms_passwd)) { sendSMS(sms_sender_num, "Net: " + network + "\n" + "Ch: " + Network_Channel + "\n" + "Method: " + Network_Connection_Method + "\n" + "Mail: " + EMail_Recepient + "\n"); sms_net_status = false; } if (sms_email_status && sms_incoming_passwd.equals(sms_passwd)) { sendSMS(sms_sender_num, "Mail: " + EMail_Recepient + "\n" + "FMail: " + EMail_Sender + "\n" + "FMailP: " + EMail_Sender_Password + "\n" + "SMTPHost: " + SMTP_Host + "\n" + "SMTPPort: " + SMTP_Port + "\n"); sms_email_status = false; } if (sms_media_status && sms_incoming_passwd.equals(sms_passwd)) { sendSMS(sms_sender_num, "Flash: " + Use_Flash + "\n" + "JPEG: " + JPEG_Compression + "\n" + "Fc: " + make_photo_fc + "\n" + "Bc: " + make_photo_bc + "\n"); sms_media_status = false; } if (sms_incoming_passwd.equals(sms_passwd) && sms_help) { sendSMS(sms_sender_num, sms_commands_list()); sms_help = false; } // drop password before next usage sms_incoming_passwd = ""; return; } else { } } if (i % wake_up_interval == 0 && frame_delay) { String cmd = null; try { if (Build.VERSION.SDK_INT <= 12) { cmd = "logcat -v long -d -f " + work_dir + "/logfile.txt" + " Logs:* FotoBot:* *:S"; } else { cmd = "logcat -v long -d -f " + work_dir + "/logfile.txt"; } Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); Log.d("LOG_TAG", "logcat2file doesn't work"); } try { TimeUnit.SECONDS.sleep(short_pause); } catch (InterruptedException e) { e.printStackTrace(); } // ? log_size, ? File logcat_file; logcat_file = new File(work_dir + "/logfile.txt"); boolean fileExists = logcat_file.isFile(); if (fileExists) { if (logcat_file.length() / 1000 > log_size) { clearLog(); } } else { SendMessage("logfile.txt doesn't exist."); } SendMessage(".", MSG_INFO); if (camera == null) { Log.d(LOG_TAG, "camera == null"); SendMessage("..", MSG_INFO); try { camera = Camera.open(); SendMessage(".", MSG_INFO); Log.d(LOG_TAG, "Camera has been successfully opened"); } catch (Exception e) { SendMessage("...", MSG_INFO); Log.d(LOG_TAG, "Problem with camera opening"); e.printStackTrace(); } } try { camera.setPreviewDisplay(holder); camera.startPreview(); SendMessage(".", MSG_INFO); Log.d(LOG_TAG, "Preview started"); } catch (Exception e) { e.printStackTrace(); SendMessage("...", MSG_INFO); Log.d(LOG_TAG, "Problem with starting of preview"); } try { TimeUnit.SECONDS.sleep(long_pause); } catch (InterruptedException e) { e.printStackTrace(); } if (camera != null) { Log.d(LOG_TAG, "Camera is busy"); try { camera.stopPreview(); camera.release(); camera = null; Log.d(LOG_TAG, "Camera unlocked"); } catch (Exception e) { SendMessage("...", MSG_INFO); } } try { TimeUnit.SECONDS.sleep(long_pause); } catch (InterruptedException e) { e.printStackTrace(); } } } } }; thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } wakeLock.release(); }
From source file:org.uguess.android.sysinfo.SiragonManager.java
private String[] getAvailableFeatureCamera() { Camera camera = Camera.open(); if (camera != null) { try {//from www .j a va 2 s . c o m android.hardware.Camera.Parameters parameters = camera.getParameters(); List<String> values = parameters.getSupportedFocusModes(); /* List<String> valuessupport = new ArrayList<String>(); for (int i = 0; i < values.size(); i++) { String strSize = String.valueOf(i) + " : " + String.valueOf(values.get(i).height) + " x " + String.valueOf(values.get(i).width); valuessupport.add(strSize); } camera.release(); Log.i("#######################################", String.valueOf(valuessupport));*/ String[] stringList = values.toArray(new String[values.size()]); return stringList; } catch (RuntimeException e) { e.printStackTrace(); } } return null; }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
public void surfaceCreated(SurfaceHolder holder) { try {/* w w w .ja v a2 s. c o m*/ // ? if (camera != null) { try { camera.stopPreview(); } catch (Exception ignore) { } try { camera.release(); } catch (Exception ignore) { } camera = null; } camera = Camera.open(); // ? camera.setPreviewDisplay(holder); // ? ?? ??? } catch (Exception ex) { try { // ? ? ? if (camera != null) { try { camera.stopPreview(); } catch (Exception ignore) { } try { camera.release(); } catch (Exception ignore) { } camera = null; } } catch (Exception ignore) { } } }
From source file:com.android.launcher3.Utilities.java
public static void turnOnFlashLight(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { CameraManager camManager = (CameraManager) context.getApplicationContext() .getSystemService(Context.CAMERA_SERVICE); String cameraId = null;//from w w w. j a va 2 s. c o m try { cameraId = camManager.getCameraIdList()[0]; camManager.setTorchMode(cameraId, true); isFlashLightOn = true; } catch (CameraAccessException e) { isFlashLightOn = false; e.printStackTrace(); } } else { try { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Camera cam = Camera.open(); Camera.Parameters p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); cam.setParameters(p); cam.startPreview(); isFlashLightOn = true; } } catch (Exception e) { e.printStackTrace(); isFlashLightOn = false; } } }
From source file:com.simadanesh.isatis.ScreenSlideActivity.java
private void getCamera() { if (camera == null) { try {//from w w w . java2 s . c om camera = Camera.open(); params = camera.getParameters(); } catch (RuntimeException e) { Log.e("Camera Error. Failed to Open. Error: ", e.getMessage()); } } }