Hello I want to save captured photo in application directory where SQLite etc reside. I don't want to make any folder and any hidden file in the SD Card. How this can be save the captured photo in application directory.

I am trying this below but it is saving in the SD card that is hidden file but I don't want this approach.

Intent cameraIntent = new Intent(
        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String capturedPhotoName = "." + System.currentTimeMillis() + ".png";
File photo = new File(Environment.getExternalStorageDirectory(),
        capturedPhotoName);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(cameraIntent, CAMERA_INTENT_REQUEST);

Thanks in advance !

有帮助吗?

解决方案

Try this method to save captured image in application storage

 public Uri setImageUri() {
        ContextWrapper cw = new ContextWrapper(getApplicationContext());
        File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
        File file = new File(directory,System.currentTimeMillis() + ".png");
        Uri imgUri = Uri.fromFile(file);
        this.imgPath = file.getAbsolutePath();
        return imgUri;
    }

Image will store at this location

/data/data/com.your.packagename/app_data/imageDir

其他提示

get URI from onActivityResult() and convert it into bytes store bytes in Database.

byte[] UserPic = null;
UserPic = Base64.decode(result.getData(), 0);

save userPic in DataBase

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top