android-hidden-camera
android-hidden-camera copied to clipboard
I need to save the image to the gallery or to any folder. Could you please help?
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.
CameraConfig().getBuild(context).setImageFile(your file).....build()
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) {
}
});
}`