Android 2.1 phone contact - android

in android 2.1 how can i read phone contact image,if no contact image is there i need to get the default one the os provide.

Just use the convenience method openContactPhotoInputStream() of the ContactsContract.Contacts class which will return an InputStream containing the contacts photo if one is set. If no photo is set it will return null in which case you should try to set android.R.drawable.ic_contact_picture as your default image.
Right. After trying it myself it looks like you can't access the private Drawables which is even discouraged. Silly me.
However you can just navigate to your android-sdk/platforms/android-4/data/res/drawable directory and copy the ic_contact_picture to your projects drawable directory. Then if the method above returns null just set that drawable as your photo.

Related

Android contact image placeholder in listview

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

android: facebook query FQL tries to retrieve the photo src from photo_src table

Recently , I realized my application can't retrieve any image src from facebook using the table photo_src
e.g. query Select pid From photo_src where size = '960X960'.
It works fine previously and able to get the source of the photo on facebook but somehow now i can't retrieve the image at all.
From the description on their website, the size property: A string representing the max size of the image returned. For example, 640X640. Note: If you want an exact dimension, use width and height
It should return a photo that maximum in the list wasn't....
Please help
Same here for my application. It looks like Facebook has made a change or introduced a bug that it no longer treats it as a parameter for max size. I used to use size='480x480'. However, it only returns with an exact match.
We should report a bug to Facebook. For me, I would likely simply remove the size parameter and select the best matched photos in my own application.

If "Image name" in database matches "Image Name" in directory, display images in gridview

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
}

String and character sequence error (force close) Android

I am facing a problem in solving this issue.
I have 30 smiley images. In a grid view I display all the 30 images. So when I select the image based on the position of the image, the corresponding special character will be displayed from SQLite DB. Before I send message to service it is like "hi :)". What I need is to replace the ":)" with the corresponding smiley image in the local folder of my project (eg. R.drawable.facea.png). I am able to fetch the data and replace ":)" with "aaaaa"(example). But when I try to replace the ":)" with Char Sequence (Image), I get 'force close error'. Where am I going wrong?
I have a function to draw image and I get image as in Character Sequence. How can I use the value in this function globally. I also tried to create a global variable and use the CS value globally. But I still get 'force close error.
You need to use a span (specifically an ImageSpan) to be able to embed bitmap in a string. I have written about this on my blog which also covers some common pitfalls.
If you still cannot get it to work I would suggest posting the precise details of what is going wrong: i.e. your code, and the stacktrace that is getting dumped to logcat.

How can I change the name of an image when inserting it to the Android gallery?

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.

Categories

Resources