android-hidden-camera icon indicating copy to clipboard operation
android-hidden-camera copied to clipboard

I need to save the image to the gallery or to any folder. Could you please help?

Open Vernica1 opened this issue 6 years ago • 3 comments

Vernica1 avatar Mar 09 '18 05:03 Vernica1

You can move the file to a different place in onImageCapture callback. See example here: https://github.com/sagan/android-hidden-camera/blob/master/app/src/main/java/me/sagan/magic/MagicService.java

Tool.java has the code to move the file.

androidnoob123 avatar Oct 18 '18 21:10 androidnoob123

CameraConfig().getBuild(context).setImageFile(your file).....build()

JhoanesFreitas avatar Nov 22 '18 20:11 JhoanesFreitas

Do not forget to add WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permsissions and to add the file autority provider to work aswell as expected by android

`@Override public void onImageCapture(@NonNull File imageFile) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options);

    saveImageToExternalStorage(bitmap);
}`

`private void saveImageToExternalStorage(Bitmap finalBitmap) { String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); File myDir = new File(root + "/locker_intruders_images"); myDir.mkdirs(); Random generator = new Random(); int n = 10000; n = generator.nextInt(n); String fname = "locker_image_" + n + ".jpg"; File file = new File(myDir, fname); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); }

    MediaScannerConnection.scanFile(this, new String[]{file.toString()}, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {

                }
            });

}`

Thisishowwedoit-2Moons avatar Jan 14 '19 13:01 Thisishowwedoit-2Moons