Advertisement
Guest User

Untitled

a guest
May 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /* for getting */
  2.  
  3. ...
  4. MarshMallowPermission marshMallowPermission = new MarshMallowPermission(this);
  5. ...
  6.  
  7. public void getPhotoFromCamera() {
  8.  
  9. if (!marshMallowPermission.checkPermissionForCamera()) {
  10. marshMallowPermission.requestPermissionForCamera();
  11. } else {
  12. if (!marshMallowPermission.checkPermissionForExternalStorage()) {
  13. marshMallowPermission.requestPermissionForExternalStorage();
  14. } else {
  15. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  16. File mediaStorageDir = new File(
  17. Environment.getExternalStorageDirectory()
  18. + File.separator
  19. + getString(R.string.directory_name_corp_chat)
  20. + File.separator
  21. + getString(R.string.directory_name_images)
  22. );
  23.  
  24. if (!mediaStorageDir.exists()) {
  25. mediaStorageDir.mkdirs();
  26. }
  27.  
  28. String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
  29. Locale.getDefault()).format(new Date());
  30. try {
  31. mediaFile = File.createTempFile(
  32. "IMG_" + timeStamp, /* prefix */
  33. ".jpg", /* suffix */
  34. mediaStorageDir /* directory */
  35. );
  36. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mediaFile));
  37. startActivityForResult(takePictureIntent, PICK_FROM_CAMERA);
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement