Android: How to save the camera result to a private file

后端 未结 2 824

I am trying to get an image from the camera and save it directly to my app\'s private files directory. For security concerns, the image should not be publicly accessible at any

2条回答
  •  盖世英雄少女心
    2021-02-09 10:19

    i had same issue, but i solved it using clipData.

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.setClipData(ClipData.newRawUri(null, contentUri));
    intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
    

    http://developer.android.com/reference/android/content/Intent.html#setClipData(android.content.ClipData)

    The ClipData in an intent is not used for Intent matching or other such operations. Semantically it is like extras, used to transmit additional data with the Intent. The main feature of using this over the extras for data is that FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION will operate on any URI items included in the clip data. This is useful, in particular, if you want to transmit an Intent containing multiple content: URIs for which the recipient may not have global permission to access the content provider.

    i hope this help you.

    Pd: Sorry for my english. :)

提交回复
热议问题