Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. private void startCapture() {
  2.  
  3. Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  4. if (cameraIntent.resolveActivity(getPackageManager()) != null) {
  5.  
  6. File photoFile = null;
  7. try {
  8. photoFile = CreateImageFile();
  9. } catch (IOException e) {
  10. e.printStackTrace();
  11. }
  12.  
  13. if(photoFile != null)
  14. {
  15. cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
  16. startActivityForResult(cameraIntent, CAMERA_CAPTURE);
  17. }
  18. }
  19. }
  20.  
  21. private File CreateImageFile() throws IOException
  22. {
  23. String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  24. String imageFileName = timeStamp + ".jpg";
  25.  
  26.  
  27. File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+edit.getText().toString());
  28. if (!f.exists()) {
  29. f.mkdirs();
  30. } else {
  31. f = new File(Environment.getExternalStorageDirectory(), edit.getText().toString() + "(2)");
  32. f.mkdirs();
  33. }
  34.  
  35. File storageDirectory = new File(new File("/sdcard/"+edit.getText().toString),imageFileName);
  36.  
  37. return storageDirectory;
  38. }
  39.  
  40. @Override
  41. public void onActivityResult(final int requestCode, int resultCode, Intent data) {
  42.  
  43. switch(requestCode)
  44. {
  45. case CAMERA_CAPTURE:
  46. if(resultCode == RESULT_OK)
  47. {
  48. Toast t = Toast.makeText(klasorAdiActivity.this,"Photo taken",Toast.LENGTH_SHORT);
  49. t.show();
  50. startCapture();
  51. }
  52. break;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement