daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public interface PhotoTaker {
  2.     Uri capturePhoto();
  3. }
  4.  
  5. public class AndroidPhotoTaker implements PhotoTaker {
  6.     private Context _context;
  7.  
  8.     @Inject
  9.     public AndroidPhotoTaker(Context context) {
  10.         _context = context;
  11.     }
  12.  
  13.     @Override
  14.     public Uri capturePhoto() {
  15.         Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  16.         if (takePictureIntent.resolveActivity(_context.getPackageManager()) != null) {
  17.             File photoFile = new File("some/path/to/a/file");
  18.  
  19.             Uri photoUri = FileProvider.getUriForFile(_context, _context.getApplicationContext().getPackageName() + ".provider", photoFile);
  20.             takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
  21.             _context.startActivity(takePictureIntent);
  22.             return photoUri;
  23.         }
  24.  
  25.         return null;
  26.     }
  27. }
RAW Paste Data
Top