While working with Android Contact ContentProvider. We have a Phone Number and we need to get the URI of the Photo of the contact associated with this phone number With the below code we can get the Contact iMage from Phone Number With the below code we can get the Name of the Contact
String imnage;
Cursor phonesCursor;
try {
Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode("Pass here phone number"));
phonesCursor = getContentResolver().query(phoneUri, new String[]{ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI}, null, null, null);
} catch (NullPointerException e) {
e.printStackTrace();
}
catch (IllegalArgumentException e){
e.printStackTrace();
}
if (phonesCursor != null && phonesCursor.moveToFirst()) {
imnage = phonesCursor.getString(0);
try {
img_profile.setImageURI(Uri.parse(imnage));
}catch (NullPointerException e){
e.printStackTrace();
}
// displayName = phonesCursor.getString(0); // this is the contact name
} else {
Log.e("no contact ", "============");
}
String str2 = null;
Cursor query = getContentResolver().query(Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(str)), new String[]{"display_name"}, null, null, null);
if (query != null) {
if (query.moveToFirst()) {
str2 = query.getString(query.getColumnIndex("display_name"));
}
if (query != null && !query.isClosed()) {
query.close();
}
}
How to get complete address from latitude and longitude?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to check Android version?
How to start a new activity on button click
Hide/Disable soft keyboard on Activity launch: Android
What is the Different Between val and var in Kotlin?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to validate email address in Android with Kotlin?
How to Exit android app on back pressed?
How to get an image resource by it's name in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Android?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is Android Fragments?
How do i load image from drawable folder in Jetpack Compose?
What is "shared preferences" in Android ?
Add Jar/Library Files as Dependency in Android Studio
What is NetworkOnMainThread Exception?
Fix Android Emulator Kill Error When Running Your App
How to convert DP to Pixel and Pixel to Dp?
What are Android Versions available?
Decompile APK Files: How to Get Source Code - RRutors Guide
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Key Points to remember while develop the Android Application.
How to Get bitmap from drawable: Android
How to find Android Device UDID or unique ID?
Open PDF in Google Drive with Intent in Android - RRutors
What is ANR? How to avoid and resolve it?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to install/ uninstall apk by command line ADB
Android Studio project R can't find
Symmetric vs Asymmetric Encryption in Android Server - RRutors
FCM Not Receiving Notifications in Android - RRutors
What is Application?
How to avoid multiple button click at same time in android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Explain Fragment Life Cycle
How to convert milli seconds to hours, minutes and seconds in Android?
How to get screen size (width,height) in Android?
Extract Date and Time from Long Type Variable - RRutors