How to share an image with a different filename on Android? - android

I have a gallery which is maintained through app and didn't want to give images a jpg extension since I didn't want images to display in phone gallery so users cannot accidentally delete them. Filenames are something like "gall.22", "gall.381", etc. In fact, there are jpeg files.
When I share one or multiple images, they are shared with their filename which is not ending with .jpg and therefore cannot be opened regularly if shared to email, Viber, etc.
Is there a way to share files with a custom name, not the original one (to add just .jpg at the end of filename) and to avoid copying file to another file with wanted name prior sharing?

I didn't want images to display in phone gallery
I think you can try another way instead of rename extension, you can create the folder to store images and create file .nomedia inside this folder. MediaScaner will ignore this folder when scan and you can share image in normal way.
to avoid copying file to another file with wanted name prior sharing
When you share a file by Uri to another app can handle directly by Uri or copy, it depends on another app handle

Related

How to determine the WhatsApp file name format for pictures?

Premise: I am using WhatsApp on Android.
Why I am asking this
I am trying to create a script that, when configured with proper arguments, would restore accidentally deleted pictures in a WhatsApp chat, if you have a copy of those files somewhere else (with potentially different file names) and you pass them to the script.
What happens when you delete an image
Normally, if you accidentally delete the image files, WhatsApp still shows you a thumbnail, but if you click on it the following pop-up appears.
Therefore, I guess it looks for a filename in the storage and it tries to load that file.
I verified this
I tested this by manually replacing an image in the "WhatsApp Images" folder with another image, and the new image shows up in the corresponding chat as expected, so this is right.
But when I did that test, I knew the file name because I manually watched the file previews using a file manager and I identified the right file, so that was easy.
So the problem is
What about deleted files? how can I try to guess the corresponding file names in order to place the file copy back where it is supposed to be?
What I already know
First of all, I know the file names have this format:
IMG-yyyymmdd-WAxxxx.jpg
Where yyyymmmmdd is a date and xxxx is a sort of sequence number.
I also know that the mapping from thumbnails to actual files is stored in the msgstore.db database file, but it can only be accessed if you have root privileges. Do you think is there any other way to predict what the file name can be without accessing that DB?

Background of URI and filepath in Android

My app needs to read an image file and store the location in a settings database.
I found how to grab an image using the ACTION_GET_CONTENT intent that opens the media selector. It returns a Uri that looks like content://media/external/images/media/78
I understand this allows saving every kind of data source, not only files. I still have two questions about that.
How is this resolved to an actual file in a folder? Is a database maintained that builds a relation between the number and the very different filename?
If the app wants a local file as a background file for this scenario, should I save this Uri in the preferences or better the real filepath?

Put files in newly created external storage folder on first launch

My Android app creates a folder on the users device's external storage on launch:
File images = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "rapical" + File.separator);
images.mkdirs();
I have around 16 image icons (.png) that I would like to place in this folder the first time the user opens the app.
What is the best practice to do this? Should I place them in the drawable folder initially and then copy them over to the newly created images folder? Not sure what approach to take!
There are two separate issues here:
What to do with images that the user adds to your app?
What to do with your starter images, for your default foods?
Using external storage for the user-added images has some implications:
Your app can survive that image no longer existing, since the user, or other apps, can delete that file at any point
Your user does not mind that the image will get picked up by other apps, such as photo galleries
Unless you specifically want these images to be user-manipulable outside of your app, I suggest that you use internal storage for the "re-sized, compressed and stored" user-supplied images. The original image might be on external storage (I assume that you are using ACTION_GET_CONTENT and/or ACTION_OPEN_DOCUMENT to get the image), but your modified copy would be private to your app.
I sincerely hope that you are using an image-loading library, like Picasso, for loading these images, since they will handle things like background threads and ListView/RecyclerView image recycling and stuff for you.
In that case, what you store in the SQLite database for your default foods needs to be something that the image-loading library can interpret, to bring in the image that you want.
In that case, I would suggest using assets/ to ship the images and file:///android_asset/... values in the database. file:///android_asset/ points to what amounts to assets/ in your project, so if you have assets/chicken_pad_thai.jpg in the project, Picasso (and any decent image-loading library) would be able to interpret file:///android_asset/chicken_pad_thai.jpg) and load the image.
This saves you from making duplicate copies of the images, saving the user disk space and time on first launch. It also means that if you replace the images in your app (e.g., you get a better photo representing chicken pad thai), the user will start seeing the updated image, without you having to do some extra work to realize that you shipped a new image and have to copy that image out to a file somewhere.
Now, suppose that you really do want the user-supplied images to be on external storage. In that case:
Probably rather than the directory that you chose, I would go with getExternalFilesDir() (a method on Context), as on API Level 19+, you do not need WRITE_EXTERNAL_STORAGE as a permission
If you want the user to be able to manipulate the images of the default foods, then copy those out to that location on first run

How can I hide some images (saved on the sdcard by my app) from the Gallery app in Android?

My app is saving some images on the SD Card, in the AppImages directory
The inbuilt gallery app is detecting these images and showing them on the gallery.
It is possible to hide these images and to be visible only for my app?
Thanks
Rename the directory from AppImages to .AppImages. The dot "hides" this folder from the system.
On an unrelated note, consider naming the folder something less generic to lessen the chance that it already exists.
You could stop the gallery from picking up your apps photos by putting a .nomedia file in the folder where they are stored. This will stop the gallery app from detecting your images, but a user still can open them in the gallery by using a file manager to navigate to the directory and selecting an image.
Hiding the images from both the user and the gallery is not possible, AFAIK.
No Need to hide the Picture.. just Rename the Extension like ".txt" it will show the pic like unsupported file

android: how to save an image in a object

What i want is that i have made a picture chooser, the image chosen i then want to save in my own object.
Like i have a class called personalFile, this file then includes all details, name, birthdate etc.. I have made it so i can update this personal file and save them to the external storage getExternalFilesDir() using an ObjectOutPutStream.
Now i have taken a picture of the person, and have browsed my way to the picture and gotten the uri path to the picture, now how do I save this file together with the rest of the information in my class?
I have tried looking but havnt found anyone doing this. The reason is also i'd like to be able to send the personal record to another phone using mms, email or alike and be able to open it there with the picture and all.
One way of doing it (albeit not the most efficient) would be to have a byte[] image; member variable in your class and read the content of your file into that byte array. You are quite likely to experience issues though if the image size is large. The other alternative would be to just copy the image file to your external storage and inside your class simply save the file name of the file. Either way, I'm not sure of the merit of saving images as part of your persistent app data (unless the images are really small).

Categories

Resources