Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. //set up an intent to take a picture
  2. private void dispatchTakePictureIntent() {
  3.  
  4. log("in dispatchTakePictureIntent()");
  5. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  6. // Ensure that there's a camera activity to handle the intent
  7. if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
  8. // Create the File where the photo should go
  9. File photoFile = null;
  10. try {
  11. photoFile = createImageFile();
  12. } catch (IOException ex) {
  13. // Error occurred while creating the File
  14. log("Exception caught. Aborting image creation" + ex);
  15. }
  16. // Continue only if the File was successfully created
  17. if (photoFile != null) {
  18. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
  19. Uri.fromFile(photoFile));
  20. startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
  21. }
  22. }
  23. }
  24.  
  25. //set up a file for the impending picture
  26. private File createImageFile() throws IOException {
  27.  
  28. log("in createImageFile()");
  29. // Create an image file name
  30. String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  31. String imageFileName = "JPEG_" + timeStamp + "_";
  32. File storageDir = Environment.getExternalStoragePublicDirectory(
  33. Environment.DIRECTORY_PICTURES);
  34. File image = File.createTempFile(
  35. imageFileName, /* prefix */
  36. ".jpg", /* suffix */
  37. storageDir /* directory */
  38. );
  39.  
  40. // Save a file: path for use with ACTION_VIEW intents
  41. mCurrentPhotoPath = "file:" + image.getAbsolutePath();
  42. return image;
  43. }
  44.  
  45. //Snippet of manifest file
  46. <uses-sdk
  47. android:minSdkVersion="18"
  48. android:targetSdkVersion="18" />
  49.  
  50. <uses-feature
  51. android:name="android.hardware.camera"
  52. android:required="true" />
  53.  
  54. <uses-permission
  55. android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  56. android:maxSdkVersion="18" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement