0

I am trying to make my app capture an image and send it over to the server, without storing in the filesystem.

If I do it like this:

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, SOME_REQUEST_CODE);

In onActivityResult I can extract the image via

Bitmap photo = (Bitmap) data.getExtras().get("data");

but this gives me only a thumbnail.

From the documentation it seems that (one of the?) ways to get a full HD image is by instructing the camera app to store the image at some external location, by adding

intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

However this obviously requires WRITE_EXTERNAL_STORAGE

Considering I don't need the image to be stored in the filesystem, as I am sending it via network anyway, I believe asking for extra storage permission is against "ask only what you need" principle. So is there a possibility to somehow get a full hd image in memory and avoid asking the user for storage permission? Perhaps there exists some special FileProvider path type for such cases?

I have found this answer: Capture image without permission with Android 6.0 but it doesn't use FileProvider (which I have to use on Android 8) and doesn't seem to be applicable to my case.

Thanks.

Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
O.W.Grant
  • 163
  • 11

2 Answers2

3

System camera app or third party camera apps cannot access your app's internal storage, neither can your app access other camera app's internal storage. Hence External Storage seems to be the only way to communicate data between your app and Camera app.

Skylark
  • 103
  • 1
  • 8
2

Just use a file provider and save to getFilesDir or getExternalFilesDir and you do not need WRITE permission or ask the user..

blackapps
  • 8,011
  • 2
  • 11
  • 25
  • Thanks! I was not aware that it doesn't require any extra permissions, as most of the tutorials on the internet mention requesting storage permission. This Worked. – O.W.Grant Jan 06 '20 at 19:27
  • is there a tutorial? I've found a lot of tutorials on FileProvider and `WRITE_EXTERNAL_STORAGE` is still used LOL. Like this one: https://agrawalsuneet.github.io/blogs/native-android-image-sharing-in-unity-using-fileprovider/ – Someone Somewhere Jul 21 '20 at 23:48
  • That is while they use getExternalStorageDirectory(). Then you need them. – blackapps Jul 22 '20 at 07:03