Stop Saving Photos Using Android Native Camera

Stop saving photos using Android native camera

check this code..

private void FillPhotoList() {  
// initialize the list!
GalleryList.clear();
String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME };
for(int i=0;i<projection.length;i++)
Log.i("InfoLog","projection "+projection[0].toString());
// intialize the Uri and the Cursor, and the current expected size.
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","FillPhoto Uri u "+u.toString());
// Query the Uri to get the data path. Only if the Uri is valid.
if (u != null)
{
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the id).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Loop each and add to the list.
GalleryList.add(c.getString(0)); // adding all the images sotred in the mobile phone(Internal and SD card)

}
while (c.moveToNext());
}
Log.i(INFOLOG,"gallery size "+ GalleryList.size());
}

and this is where the method is doing all magic

 /** Method will check all the photo is the gallery and delete last captured and move it to the required folder.
*/
public void movingCapturedImageFromDCIMtoMerchandising()
{

// This is ##### ridiculous. Some versions of Android save
// to the MediaStore as well. Not sure why! We don't know what
// name Android will give either, so we get to search for this
// manually and remove it.
String[] projection = { MediaStore.Images.ImageColumns.SIZE,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATA,
BaseColumns._ID,};
// intialize the Uri and the Cursor, and the current expected size.

for(int i=0;i<projection.length;i++)
Log.i("InfoLog","on activityresult projection "+projection[i]);
//+" "+projection[1]+" "+projection[2]+" "+projection[3] this will be needed if u remove the for loop
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","on activityresult Uri u "+u.toString());

if (CurrentFile != null)
{
// Query the Uri to get the data path. Only if the Uri is valid,
// and we had a valid size to be searching for.
if ((u != null) && (CurrentFile.length() > 0))
{
//****u is the place from data will come and projection is the specified data what we want
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the size).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Check each area in the gallery we built before.
boolean bFound = false;
for (String sGallery : GalleryList)
{
if (sGallery.equalsIgnoreCase(c.getString(1)))
{
bFound = true;
Log.i("InfoLog","c.getString(1) "+c.getString(1));
break;
}
}
// To here we looped the full gallery.
if (!bFound) //the file which is newly created and it has to be deleted from the gallery
{
// This is the NEW image. If the size is bigger, copy it.
// Then delete it!
File f = new File(c.getString(2));

// Ensure it's there, check size, and delete!
if ((f.exists()) && (CurrentFile.length() < c.getLong(0)) && (CurrentFile.delete()))
{
// Finally we can stop the copy.
try
{
CurrentFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(f).getChannel();
destination = new FileOutputStream(CurrentFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally
{
if (source != null)
{
source.close();
}
if (destination != null)
{
destination.close();
}
}
}
catch (IOException e)
{
// Could not copy the file over.
ToastMaker.makeToast(this, "Error Occured", 0);
}
}
//****deleting the file which is in the gallery
Log.i(INFOLOG,"imagePreORNext1 "+imagePreORNext);
Handler handler = new Handler();
//handler.postDelayed(runnable,300);
Log.i(INFOLOG,"imagePreORNext2 "+imagePreORNext);
ContentResolver cr = getContentResolver();
cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, BaseColumns._ID + "=" + c.getString(3), null);

break;
}
}
while (c.moveToNext());
}
}

}

Avoid that the gallery saves the picture taken with the camera in Android

I found this solution:
Stop saving photos using Android native camera

The idea is to check which files are in the gallery just before taking the picture and just after it, delete that one that is new.

It's not the cleanest solution but it works.

Internal App Camera Photos Improperly Saved to Gallery

I want these photos to stay 100% internal to my own app for privacy reasons

Then you should not be using ACTION_IMAGE_CAPTURE. By definition, that delegates the photo-taking to an arbitrary app, one of hundreds of possible apps based on device and user.

Instead, take the picture yourself, in your own app, either using the camera APIs directly or by using a library that wraps them.

On certain devices (not all of them) the photos taken within my app are being copied into the camera roll on the phone

Some camera apps will save the photos where they want, possibly in addition to copying the photo to your EXTRA_OUTPUT location. That is up to the developers of those camera apps, not you. Arguably, that behavior is a bug, but you have no practical means of getting any camera app developer to fix that bug, let alone developers of all buggy camera apps.

How can I stop images generated by my application from showing in the gallery?

add an empty file called .nomedia in the directory where you store the images

React-native-camera don't want to save images

The correct answer is Edit #2!

You can open an issue at our repo: https://github.com/react-native-community/react-native-camera

The image is saved in your app's cache directory.

When the promise is resolved, the object contains an uri, the path to the image. Or you can pass the option base64: true, to receive the base64 representation of your image from the takePictureAsync promise.

With the base64 string, you can send it to your server. That is what we do in our apps.

Edit: if you really do not want it saved in your app's cache directory, we could create an option in the takePictureAsync method to do it. Feel free to open an issue about this in our repo as a feature request.

Edit #2: Correct answer:
You are using RCTCamera, which saves the image on the device by default.

Use the prop captureTarget, passing the value Camera.constants.CaptureTarget.temp.
So:

<Camera
...
captureTarget={Camera.constants.CaptureTarget.temp}
...
</Camera>

Saving photos to DCIM/Camera - why aren't they showing up in Photos app?

After the photo has been saved, add this line to let the Photos app know there are new photos:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + photo.getAbsolutePath())));


Related Topics



Leave a reply



Submit