Icon for contacts when contact is used by people app - android

I have tried a lot to add icon in connections of contacts of android phone whne that contact is used by my app.But I not able to get even a single reference to do it.Please do the favourable.I tried to use this link
But not get any solution as its not properly explained.Simply I have to add icon like whats app goggle plus in phone contact if its used by my app

This code works pretty well to get a photo, if I understand you correctly:
Uri my_contact_Uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
InputStream photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(cr, my_contact_Uri, true);
BufferedInputStream buf = new BufferedInputStream(photo_stream);
Bitmap my_btmp = BitmapFactory.decodeStream(buf);
buf.close();
return my_btmp;
Look at this question: Get high-res contact photo as bitmap below API level 14 Android for more info.

Related

How to Edit Contact Photo

I'm wanting to use Kotlin to update a contact with a new Bitmap bmp as a profile picture. I found documentation for editing contacts, but I can't find a field on the intents page for changing the photo. Any stack overflow solutions I found all involve strange ways of updating it, even though the developer page encourages using intents. What's the best way to change contact photos?
First of all, never use bmp, it's such a huge file you don't want to put bmp photos in any database.
So, now to insert a new picture to a specific raw-contact, and assuming you have some standard picture file (jpeg/png) on hand, you do this:
val rawContactPhotoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, yourRawContactId), // note that this must be a RAW-contact-id, not a contact-id
RawContacts.DisplayPhoto.CONTENT_DIRECTORY
) // this is the url the represents a RawContact picture
try {
val bytes = yourPictureFile.toByteArray() // get a byte array from your pic
val fd = context.contentResolver.openAssetFileDescriptor(rawContactPhotoUri, "rw")
val os = fd?.createOutputStream()
os?.write(bytes)
os?.close()
fd?.close()
} catch (e: IOException) {
// Handle the error
}

Android:Retrieving Image or Thumbnail from ContactsProvider for API level 10

I would like to retreive the full size Contact Image from the Android ContactsProvider for API level 10 and above.
From my understanding there is no way to test whether I get the full size photo using PHOTO_URI(API level 11) which seems to be populated either using the PHOTO_FILE_ID(API level 14).Then there is PHOTO_ID(API level 5) which could hold a reference to the photo or not,if not fallback to PHOTO_URI or PHOTO_THUMBNAIL_URI(API level 11).I use 2.3.3(API level 10).This is all confusing and perplexing.
I use DISPLAY_PHOTO(API level 14),it is gauranteed to give me a null value or crash below ICS(havent tested yet).
I also understand that some images from say 3rd party applications that sync with ContactsProvider cannot be retreived and are only for the use of the Android ContactsProvider which means that the user sees the image in the Contacts app of the phone but not in the my app.
Any solution you might know of that could help me always retreive the full size api and not the thumbnail for API level 10 and above?
Can I atleast retreive the thumbnail of the Contact for API level 10?
I found a method on this post that works for obtaining the thumbnail for API levels 5 and above using the ContactsContract API,check here for more information:
public static Bitmap loadContactPhoto(ContentResolver cr, long id) {
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
if (input == null) {
return getBitmapFromURL("http://thinkandroid.wordpress.com");
}
return BitmapFactory.decodeStream(input);
}

Storing contact photos with a possibility to retrieve original image in future

According to the official documentation which contains information about contact's photo handling (Android 4.0):
Large photos
Android now supports high resolution photos for contacts. Now, when
you push a photo into a contact record, the system processes it into
both a 96x96 thumbnail (as it has previously) and a 256x256 "display
photo" that's stored in a new file-based photo store (the exact
dimensions that the system chooses may vary in the future). You can
add a large photo to a contact by putting a large photo in the usual
PHOTO column of a data row, which the system will then process into
the appropriate thumbnail and display photo records.
So, I would like to know if I store a photo with the size of 400x400 px, is there any possibility to retrieve this photo with it's original size, or I have to be glad only having a photo with decreased size?
Try this example:
public void writeDisplayPhoto(long rawContactId, byte[] photo) {
Uri rawContactPhotoUri = Uri.withAppendedPath(
ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
RawContacts.DisplayPhoto.CONTENT_DIRECTORY
);
try {
AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
rawContactPhotoUri,
"rw"
);
OutputStream os = fd.createOutputStream();
os.write(photo);
os.close();
fd.close();
} catch (IOException e) {
// Handle error cases.
}
}
Using file descriptors you can read/write contact photo. Also I think you need store thumbnail of your photo to contact
For more info see ContactsContract.RawContacts.DisplayPhoto class
Simple solution:
Login to your gmail account from any PC, then search for "contacts"
From within contacts page: enter the contact name you want to search for
Click on the contact that you want & select "save image..."
Note: I don't know if there is a higher quality version inside the phone but I'm still working on it.

Getting profile pic from Facebook and display it in Android App

I'm trying to get a users facebook profile pic using the FB api.
My way of doing this isn't working... first I make a request like this:
String str = facebook.request("me/picture");
Next I create an inputstream from the string str so I can decode it with a bitmapfactory
InputStream is = new ByteArrayInputStream(str.getBytes());
Bitmap bm = BitmapFactory.decodeStream(is);
iv.setImageBitmap(bm);
This never displays the image!
Haven't been able to find much about this. Any help would be appreciated.
I fixed this by just using HTTPGet to the url The first time I tried it I got a 404 error but when I rewrote it it worked!

Uploading images via http post while preserving EXIF data in Android

I am brand new to Android development, and have run into an issue with my first major app that I would very much appreciate help on. The goal of this app is to allow the user to select an image stored on the phone, and upload that image to a server via a http post method, taking the JPEG binary data as a parameter. The catch is that I need to preserve the EXIF data on this as well. I currently have pushed an image onto my emulator's sdcard, and used a basic app to confirm that it is there with the EXIF data.
Here is what I've got so far:
To provide the user with a choice of images, and as a result obtain the image Uri, I use:
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);
In my activity result code, I obtain my Uri with:
Uri selectedImage = data.getData();
I use this to get a bitmap of the image and display it to the user as a preview.
Here is where I get stuck, as I'm not sue how best to upload it. I have looked a lot at this example in hopes of doing something similar, but he seems to be just compressing a bitmap and sending it, which would probably destroy the EXIF data I need, plus I can't even seem to get that to work.
This is the code I'm trying right now, which given my low experience with such things may be entirely wrong:
Uri selectedImage = data.getData();
InputStream imageInputStream=this.getContentResolver().openInputStream(selectedImage);
String str=imageInputStream.toString();
byte[] imageBits=str.getBytes();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("where I am sending it");
ByteArrayBody toUpload = new ByteArrayBody(imageBits, "androidpic.jpg");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("userImage", toUpload);
reqEntity.addPart("FileName", new StringBody("android pic"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
This of course does not seem to work.
Does anyone have experience uploading jpegs from the phone like this who could give me some pointers? Any help would be greatly appreciated.

Categories

Resources