How do I save data from Camera to disk using MediaStore on Android?

后端 未结 5 1222
予麋鹿
予麋鹿 2020-11-30 03:43

For my application, I\'d been using my own Camera class for taking images and my own database but soon enough I couldn\'t really keep up with changes and I decided to use th

5条回答
  •  渐次进展
    2020-11-30 04:17

    The below code will start the default camera and have the camera save the image to the specified uri. The key is to put the extra "MediaStore.EXTRA_OUTPUT" along with the desired uri.

    File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Images/" + image_name + ".jpg");
    Uri imageUri = Uri.fromFile(file);
    
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    
    startActivityForResult(intent, 0);
    

提交回复
热议问题