Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Save Image from Custom Camera to Custom Folder on SD Card
    primarykey
    data
    text
    <p>I have a custom camera that I would like to save the captured images from it on a folder in my sd card. I've viewed a few examples, but for whatever reason I'm just not getting anything to save (folder or image). Below is my code. If anyone can help, that would be great! I do already have the android.permission.WRITE_EXTERNAL_STORAGE added to my manifest.</p> <pre><code>button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mCamera.takePicture(null, null, mPicture); mCamera = getCameraInstance(); mPreview = new CameraPreview(CameraActivity.this, mCamera); FrameLayout preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(mPreview); } private Camera getCameraInstance() { // TODO Auto-generated method stub Camera c = null; try { c = Camera.open(); } catch (Exception e) { } return c; } private PictureCallback mPicture = new PictureCallback() { public void onPictureTaken(byte[] datas, Camera camera) { // TODO Auto-generated method stub File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(datas); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } } }; private File getOutputMediaFile() { // TODO Auto-generated method stub File root = Environment.getExternalStorageDirectory(); File myDir = new File(root + "/NewFolder/"); myDir.mkdirs(); if (myDir.exists()){ } Random generator = new Random(); int n = 10000; n = generator.nextInt(n); String fname = "Image"+ n +".jpg"; File file = new File (myDir, fname); Uri uriSavedImage = Uri.fromFile(file); sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()))); i.putExtra("output", uriSavedImage); return file; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload