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 do I check in SQLite whether a table exists?
What is ANR? How to avoid and resolve it?
How to get complete address from latitude and longitude?
What is Android?
How to Generate signed apk with android studio
How To Set Text Color Programmatically Android TextView?
How to validate email address in Android with Kotlin?
What is NetworkOnMainThread Exception?
How to Exit android app on back pressed?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is Context?
How to install/ uninstall apk by command line ADB
What is the difference between match_parent and fill_parent?
How to find Android Device UDID or unique ID?
How to reduce APK package size?
How to copy database from assets folder in android using kotlin
Decompile APK Files: How to Get Source Code - RRutors Guide
What are the notifications available in android?
Hide/Disable soft keyboard on Activity launch: Android
Fix Play Store Rejection Due to SMS Permission - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get an image resource by it's name in android?
What is ANR in android?
How to get screen size (width,height) in Android?
Permission denied for window type 2010 in Marshmallow device
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to start a new activity on button click
How to convert DP to Pixel and Pixel to Dp?
Fix Android Emulator Kill Error When Running Your App
Explain Fragment Life Cycle
Android Studio project R can't find
What is the Different Between val and var in Kotlin?
How to Get bitmap from drawable: Android
What are Android Versions available?
How can i comment inside xml file in android studio?
What happens next when the device switches between portrait and landscape?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Check List for Generate Signed APK Android
Key Points to remember while develop the Android Application.
How to check Android version?