-1

Is there possibility just to open external camera application and let it take picture, save it and notify media_scanner for me? I'm googling for a long time now and everything I found are just topics about calling camera intent and need to process taken image myself.

I don't want to have need for WRITE_STORAGE and CAMERA permissions in my app, I just want to access gallery and direct user to external camera if needed.

PS In case anyone wants to downwote this question, please, explain yourself after read it one more time carefully. Thanks!

shmoula
  • 1,053
  • 2
  • 10
  • 33
  • "need to process taken image myself" -- what "process" are you referring to? `ACTION_IMAGE_CAPTURE` will save the image for you if you supply `EXTRA_OUTPUT` (and the camera app doesn't have bugs), and you do not need any permissions to use `MediaScannerConnection` and `scanFile()` to notify the media scanner. – CommonsWare Jul 29 '15 at 14:30
  • sry, was afk. Sure, I'm passing Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) -> Uri as an EXTRA_OUTPUT parameter. The file is physically there if I check it but it looks like no media_scanner is called - picture does not appear in standard gallery nor in my MediaStore.Images.Media.EXTERNAL_CONTENT_URI loader. Should I force scanner manually in my onActivityResult()? – shmoula Jul 29 '15 at 16:17

1 Answers1

0

As noted in my comment, ACTION_IMAGE_CAPTURE will save the image for you if you supply EXTRA_OUTPUT (and the camera app doesn't have bugs), and you do not need any permissions to use MediaScannerConnection and scanFile() to notify the media scanner. There is no requirement, as part of ACTION_IMAGE_CAPTURE processing, for the camera app to arrange for your file to be indexed, in part because the camera app does not know if that is what you want.

Sure, I'm passing Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) -> Uri as an EXTRA_OUTPUT parameter

That will not work reliably. EXTRA_OUTPUT needs to point to a file to be written to, not a directory. If you provide a directory, I would expect behavior to be rather variable.

Should I force scanner manually in my onActivityResult()?

That seems like a fine plan.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sure, that's a directory, I'm creating file inside like it's mentioned in Google docs here http://goo.gl/BCkWmN – shmoula Jul 29 '15 at 16:26
  • OK, calling sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri)); in onActivityResult() helped, thanks for kicking me on the right way. – shmoula Jul 29 '15 at 16:33