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();
}
}
What happens next when the device switches between portrait and landscape?
How To Set Text Color Programmatically Android TextView?
How to Get bitmap from drawable: Android
What is NetworkOnMainThread Exception?
What is the Different Between val and var in Kotlin?
What is ANR? How to avoid and resolve it?
How to stop EditText focus at Activity startup in Android?
How do I generate random numbers in Dart?
What is Android Fragments?
Check List for Generate Signed APK Android
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Context?
How to get complete address from latitude and longitude?
How to validate email address in Android with Kotlin?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to Use Deprecated Handler() in Android - RRutors Guide
Open PDF in Google Drive with Intent in Android - RRutors
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is "shared preferences" in Android ?
How to Generate signed apk with android studio
How to reduce APK package size?
Decompile APK Files: How to Get Source Code - RRutors Guide
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to convert milli seconds to hours, minutes and seconds in Android?
Extract Date and Time from Long Type Variable - RRutors
How to get screen size (width,height) in Android?
How to install/ uninstall apk by command line ADB
How can i comment inside xml file in android studio?
How to get a contact image using a phone number in android?
What is ANR in android?
What is the difference between match_parent and fill_parent?
How to copy database from assets folder in android using kotlin
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What are the notifications available in android?
How to start a new activity on button click
Set Activity to Fullscreen Mode in Android - RRutors
Fix Android Emulator Kill Error When Running Your App
Android Studio project R can't find
What are Android Versions available?