Unwanted image being saved in gallery - android

I have used an answer from here
How should I give images rounded corners in Android?
However when created the picture with rounded edges it is being saved in my camera gallery as well as in a custom location that I have specified, any reason why this would happen or anyway to get rid of it automatically?
I don't want a picture being saved here.

Images are not saved in your device gallery - the gallery just displays all the images that are on your phone, UNLESS they are in storage associated with particular application. Use the following method do determine where you should save the images.
private File getAbosoluteFile(String ralativePath, Context context) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return new File(context.getExternalFilesDir(null), ralativePath);
} else {
return new File(context.getFilesDir(), ralativePath);
}
}
It will store them in external storage associated with your application and they will seize being displayed in the device's gallery. Try this out with new image, because images are cached for a long time in the gallery application.

Related

Flutter: Capture photo - Save to Gallery - Read photos from Gallery

I'm new in flutter.
Hope my issue below will be same your issue in the past. And you can help me for this:
My situation is:
My app will capture an photo (using package camera: ^0.5.8+2). Then, this photo will be saved on gallery of user device (using package gallery_saver: ^2.0.1). Finally, I will open the gallery (using package photo_manager: ^0.5.7) to pick some photos which I captured before ==> This flow is really clear and simple, right? ^_^
But, I have already trap at this issue:
After I captured an photo, then open the gallery from my app, I can't see this photo (Althought I can see this photo on device gallery). I also print the log on console to make sure that: my recently photo was got by my app. But, I still see nothing, it's mean my app also can't read this recently photo.
So, what do I wrong? Or what am I missing? Everyone who have experience about this issue help me, pls!
Below is my source code:
This is function to take photo by using camera package (https://pub.dev/packages/camera)
/// Take an photo
_takePhoto() async {
try {
if (_numberPhotoTaken < widget.maxTaken) {
/// Path
var file = "${DateTime.now().toString()}.jpg";
var temporaryDir = (await getTemporaryDirectory()).path;
var pathSaved = join(temporaryDir, file);
/// Take photo
await _cameraController.takePicture(pathSaved);
/// save to gallery
GallerySaver.saveImage(pathSaved, albumName: galleryFolder).then((ok) {
if (ok) {
setState(() => _numberPhotoTaken++);
}
/// remove temporary file
File(pathSaved).delete();
});
} else {
AppDialog.inform(
this.context,
textLocale("Reached the maximum number of photos", this.context),
() {});
}
} on CameraException catch (e) {
} on Exception catch (ex) {
}
}
This is function to load asset from gallery by using photo manager package (https://pub.dev/packages/photo_manager)
/// fetching gallery's asset
/// return: list of asset entity in specific page
Future<List<GalleryEntity>> _fetchGalleryPaging() async {
/// load all assets in one album list
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
onlyAll: true, type: RequestType.common);
List<AssetEntity> page = await albums[0].getAssetListPaged(_currentPage, widget.perPage);
/// return gallery entity list
return page.map<GalleryEntity>((e) => GalleryEntity(asset: e)).toList();
}
I'm currently test on my android device
When I open gallery on device, I wonder: the new photo which I have just captured not be arranged right (the newest photo must be at the end of gallery). After a few time (I'm not sure how many time), device gallery will auto refresh, and my recently photo will be arranged in the right way (it's at the end of gallery). And my app will read this photo perfectly (so strange for me)
UPDATE: one more thing, my photo will be saved into a separated folder in gallery
If you read till this line. I'm so appreciate about that. And I hope among of you have experience to solve this issue
Thanks all guys,
After a few time I made searching about my issue. I find out the main problem is the external storage was not rescan when I did an capturing photo, so my flutter app can not be display the new photo on gallery.
The solution for this issue is the package:
https://github.com/hui-z/image_gallery_saver
I'm not sure about the effective of this package, but for my scene, it's work as perfect as I wish.
Hope this help for anyone who also face same issue like me
Thanks all

How do we know if an ImageView is updated in Android?

I have a form, where I have a imageview and other two text fields. This imageview will be updated with the pic a user chooses(either from gallery or by taking a pic). I will be saving this image in internal storage and other two text fields and saved image path in SQLite DB.
User has option of not choosing any image. In that case I should not save any image, coz I simply be wasting storage. For that how do I distinguish when a user chooses or not to upload any image?
int NEW_PIC=1;
int NO_CHANGE=0;
initialise
img_camera.setTag(AppConfig.NO_CHANGE);
when Changed set
img_camera.setTag(AppConfig.NEW_PIC_ADDED);
if ((int) iv_userImage.getTag() == NEW_PIC_ADDED) {
//New Image Added
}
else{
//Not New
}

Android display images when offline once downloaded using fresco

I want fresco to download and save images to sd-card when connected to internet.
Later when offline and even if cache is cleared, still I need fresco to show saved images.
Is this possible? If yes, how?
Simply saving images to disk cache doesnt seem to work when cache is cleared.
Fresco caches images for you. If you are offline, the images should still be displayed. You should not need to do anything.
However, when the cache is cleared (e.g. when the user presses the button or when device space is low), images are obviously deleted from the cache - which is the desired behavior that should not be changed.
There are 2 options: save selected items, move the cache
Save selected items
If you want to persist selected images (e.g. a "Save" button), you can get the encoded image and save it somewhere on the device.
You should not do this for all images since they will be on the disk 2 times and clearing the cache / uninstalling the app will leave 1 copy on the device.
Something like this could work:
DataSource<CloseableReference<PooledByteBuffer>>
dataSource = Fresco.getImagePipeline().fetchEncodedImage(imageRequest, callerContext);
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<PooledByteBuffer>>() {
#Override
protected void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
CloseableReference<PooledByteBuffer> encodedImage = dataSource.getResult();
if (encodedImage != null) {
try {
// save the encoded image in the PooledByteBuffer
} finally {
CloseableReference.closeSafely(encodedImage);
}
}
}
#Override
protected void onFailureImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
// something went wrong
}
}, executorService);
}
More information on how to use the pipeline to get the encoded image: http://frescolib.org/docs/using-image-pipeline.html
Move the cache
Keep in mind that this will persist the cache when it is moved to an external directory, so be careful since this will leave files when the app is uninstalled.
Fresco also allows you to supply a custom DiskCacheConfig and you can create a new DiskCacheConfig.Builder and call setBaseDirectoryPath(File) to change the path to a different folder (e.g. one on the SD card) and you can also change the directory name with setBaseDirectoryName(String)
More information on how Fresco does caching: http://frescolib.org/docs/caching.html
You need to manually save the images to disk when downloaded. When displaying the images, check if image is in disk: if its not, download from url (and save to disk).

Take photo of given size Android

I'm developing an application that takes a photo and saves it in Android/data/package/files. I would like to reduce storage used, so I would like to resize the photo before saving it. For the moment I'm calling new intent passing as extra the output path. Is possible to pass also the size wanted or is possible to have the bitmap before saving it?
public void takePicture(View view){
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(getPath(nameEdit.getText().toString()));
path = f.getAbsolutePath();
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
if (pictureIntent.resolveActivity(getPackageManager())!=null){
startActivityForResult(pictureIntent,REQUEST_IMAGE_CAPTURE);
}
}
Is possible to pass also the size wanted
No.
is possible to have the bitmap before saving it?
Not really. You could write your own ContentProvider and use a Uri for that, rather than a file. When the camera app tries saving the content, you would get that information in memory first. However, you will then crash with an OutOfMemoryError, as you will not have enough heap space to hold a full-resolution photo, in all likelihood.
You can use BitmapFactory with inSampleSize set in the BitmapFactory.Options to read in the file once it has been written by the camera, save the resized image as you see fit, then delete the full-resolution image. Or, skip EXTRA_OUTPUT, and you will get a thumbnail image returned to you, obtained by calling getExtra("data") on the Intent passed into onHandleIntent().

how to attach image from assets folder loaded in gallery view to email android?

i'm new to android.
I have some images in assets folder.I know/and have already loaded them in a gallery view.
So my problem is :
when I open gallery,my images from assets folder gets loaded in gallery view.But when to send it through email.It doesn't gets attached to email.I want them to get attached to email (one at a time) without saving them to Sd card.
can anyone help me with my problem?
Not sure if this will work with assets, but use flag Intent.FLAG_GRANT_READ_URI_PERMISSION while launching the Email app.

Categories

Resources