I have to store image id for the image captured from camera.
Through this image id I can access its thumbnails and actual image considering those image resides on device already.
I have implemented this with image picker intent, but don't know if this is possible with Camera intent. The data when printed gives null, which for me doesn't seems to be notified to Mediastore.
Any idea or solution is appreciated.
Anyways, for a while I am implementing a workaround until I find the conventional way of doing it.
Currently my self solution is, to get a list of all the image IDs of both stages, before taking photo and after taking the photo. The new ID in new list is the ID I am looking for, when filtered with old list.
below is my code snippet.
private String getDiscrepantId(ArrayList<String> old_lst, ArrayList<String> new_lst){
for(int i=0; i<old_lst.size(); i++){
if(new_lst.contains(old_lst.get(i))){
new_lst.remove(old_lst.get(i));
}
}
return new_lst.get(0);
}
I hope there must be some better way to achieve this, which I believe someone will share it soon.
Related
My app contains the camera functionality. I have develop the app.
As the app get starts one ListView of stations will popup(Like Station1, Station2,Station3....) & user has select one item from it. Then it will open the camera activity. So once the user took a picture, the image has to be stored like 'Station1_1', 'Station1_2', 'Station2_1', 'Station2_2' inside gallery. I have covered with the initial station name(Station1, station2..). But how do I store the last portion because it contains the sequence for each Station. So is there any way to save the images by 1,2,3....?
Thanks in advance.
There is a way but it isn't appropriate. If you just want to store each image having last portion is different then you can do in the following ways:-
You can call API for just handling counter.
You can store counter in PREFERENCE, but it won't work perfect if user clear data then new images were override old one.
You can store TIMESTAMP as end portion and it is appropriate way.
I have an idea about the widget that when I click on widget, the text & image will refresh randomly. I have done this with text, but my images are stored on Firebase and I want to take these random images and display them in an ImageView. So how I can do this?
Screenshot of my Firebase Storage:
Screenshot of my App:
As an alternative to #Bernd's answer: You could modify your image names to a standard naming scheme using incremental numbers. You could then retrieve the image URLs dynamically, like so:
Example image names:
image_0.jpg
image_1.jpg
image_2.jpg
image_3.jpg
Some example Java code to generate a random image filepath:
//The amount of images you have stored
int maxImages = 4; //Amount of images
Random random = new Random();
//Randomly generate a filepath to an image
String imageFilePath = "image_" + random.nextInt(maxImages) + ".jpg";
You can then use your generated imageFilePath with FireBase Storage's getDownloadUrl() to retrieve the proper download URL. You can then pass the URL to Glide, Picasso, or another image download library to load it into your ImageView.
Advantages
Only have to use Firebase Storage to achieve your goal
Less overhead on the database, don't have to maintain a list of images there
Disadvantages
You have to control the image names tightly, no custom image names
You have to have a fixed number of images
Could break if you delete an image without changing other image names
Retrieving the URL will throw an exception if the image couldn't be found (e.g. if the random number is out of bounds)
To randomly select an image from Firebase storage, you need to have a list of download url's of the files somewhere. As described in this answer, there is no Api to get a list of these pictures at the moment, so you will have to store the urls of them somewhere.
One possibility for this is to simply add the urls
of the files to Firebase database.
When you want to select a random image, you could go through the database,
and select a random url from this list.
To actually display them in the ImageView, you can use a library like Glide, to make this process easier. The FriendlyPix example App by Firebase, shows how to do this.
I have an activity with a listview and a custom adapter. Retrieving the contact information and the image is not the problem. I can not display an alternative image if there is not one for the contact.
Checking if the URI is NULL does not work for me.
I am retrieving the URI of the android contacts and the resulting URI have the format
content://com.android.contacts/contacts/XXX/photo
where XXX is a number. The resulting URI is only NULL for default contacts added like emergency numbers, so checking for NULL to replace the image with a placeholder image works only on those numbers. For all other contacts that have not set an image i want to check the filesize of the contact image.
File f = new File(uri.getPath());
long size = f.length();
String str = Long.toString(size);
Using the above commands results are always 0, it doesn´t matter if there is a photo or not.
How can i check the filesize correctly? or how can i check if the resulting photo is empty.
Thanks for helping
I encourage you to use Facebook Fresco library. You will be able to provide place holder image aswell as error image for image view
Use any famous image loaders like Universal image loader or picasso lib. This libs will handle every thing, its have some methods for putting error images. And you can directly put your contact URl in this libs.
They will support all kinds of url. you can check here
The idea to check if the file exists led me to this post where it was answered
detect if contact has photo
.getDrawable() == null
gets the correct result.
thanks for all comments
I am new to android and the concepts of programming, I'm a bit stuck on something atm and could do with a push in the right direction.
I am developing an app that has a function allowing users to capture an image, store that image in the app's file system, and store a reference to that image in an sqlite database. I explain this HERE, and got some good feedback as to how I would go about storing the reference in the database...I chose to just store the file name of the image.
The real issue here is that I do not know how to go about retrieving the image reference from the database and display the images in a grid view. The way I think this can work is to have a query something like:
IF (image name in database == image name in file system)
{
Display those images only
}
I don't know how to implement this, any help or insight will be greatly appreciated, thanks!
you can do something like this:
retrieve all the image names from the data base and then check if they exists on file system or not.
if(new File(FOLDERPATH + File.separator + file_name_in_db).exists()) {
// add file to list to be set in grid view adapter
}
When I take a picture with Android's camera app, it is inserted in the gallery with a name identical to it's creation date/time, like "2010-02-04 16.36.15.jpg"
In my app i take my own pics, and insert to the gallery them using
android.provider.MediaStore.Images.Media.insertImage(
ContentResolver cr, Bitmap source, String title, String description);
However, in the gallery they appear with a name that seems to be the time stamp of their creation in millis, like "1265323665851.jpg" , no matter what i put in the tittle argument.
I need them to have the same name they would get from Android's camera app, so that they will be properly ordered.
Is there a way to do so?
Thanks in advance.
Old question. I eventually found out the order of the pictures was about a field in the database.