diff --git a/src/org/kde/kdeconnect/Helpers/ContactsHelper.java b/src/org/kde/kdeconnect/Helpers/ContactsHelper.java index 0f4574b4..d2085070 100644 --- a/src/org/kde/kdeconnect/Helpers/ContactsHelper.java +++ b/src/org/kde/kdeconnect/Helpers/ContactsHelper.java @@ -21,12 +21,17 @@ package org.kde.kdeconnect.Helpers; import android.content.Context; +import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; import android.provider.ContactsContract.PhoneLookup; +import android.util.Base64; +import android.util.Base64OutputStream; import android.util.Log; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -75,5 +80,29 @@ public class ContactsHelper { return contactInfo; } + + public static String photoId64Encoded(Context context, String photoId) { + AssetFileDescriptor fd = null; + Uri photoUri = Uri.parse(photoId); + Uri displayPhotoUri = Uri.withAppendedPath(photoUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO); + + byte[] buffer = null; + Base64OutputStream out = null; + ByteArrayOutputStream encodedPhoto = null; + try { + encodedPhoto = new ByteArrayOutputStream(); + out = new Base64OutputStream(encodedPhoto, Base64.DEFAULT); + InputStream fd2 = context.getContentResolver().openInputStream(photoUri); + buffer = new byte[1024]; + int len; + while ((len = fd2.read(buffer)) != -1) { + out.write(buffer, 0, len); + } + return encodedPhoto.toString(); + } catch (Exception ex) { + Log.e("ContactsHelper", ex.toString()); + return new String(); + } + } } diff --git a/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java b/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java index 5c494db3..23105367 100644 --- a/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java @@ -102,8 +102,14 @@ public class TelephonyPlugin extends Plugin { NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY); if (phoneNumber != null) { np.set("phoneNumber", phoneNumber); + } + + if (contactInfo.containsKey("name")) { np.set("contactName", contactInfo.get("name")); } + + if (contactInfo.containsKey("photoID")) { + np.set("phoneThumbnail", ContactsHelper.photoId64Encoded(context, contactInfo.get("photoID"))); } switch (state) {