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 screen size (width,height) in Android?
What is the difference between match_parent and fill_parent?
Fix Play Store Rejection Due to SMS Permission - RRutors
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to convert milli seconds to hours, minutes and seconds in Android?
Open PDF in Google Drive with Intent in Android - RRutors
Permission denied for window type 2010 in Marshmallow device
Check List for Generate Signed APK Android
What is NetworkOnMainThread Exception?
Key Points to remember while develop the Android Application.
Explain Fragment Life Cycle
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to save activity State in Android?
What are Android Versions available?
How to reduce APK package size?
Set Activity to Fullscreen Mode in Android - RRutors
What is Application?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is ANR? How to avoid and resolve it?
How do I generate random numbers in Dart?
How to start a new activity on button click
How to Get bitmap from drawable: Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is Android?
How to find Android Device UDID or unique ID?
What happens next when the device switches between portrait and landscape?
Hide/Disable soft keyboard on Activity launch: Android
What is "shared preferences" in Android ?
Add Jar/Library Files as Dependency in Android Studio
How to Use Deprecated Handler() in Android - RRutors Guide
Extract Date and Time from Long Type Variable - RRutors
What is ANR in android?
How can i comment inside xml file in android studio?
How to avoid multiple button click at same time in android?
How to copy database from assets folder in android using kotlin
How to check Android version?
How to convert DP to Pixel and Pixel to Dp?