avoid showing some warnings if READ_CONTACTS permission isnt given

This commit is contained in:
tibbi 2020-04-13 11:28:19 +02:00
parent fec69ff4c3
commit 8f913867f4
1 changed files with 8 additions and 0 deletions

View File

@ -433,6 +433,10 @@ fun Context.getNameAndPhotoFromPhoneNumber(number: String): NamePhoto? {
}
fun Context.getNameFromPhoneNumber(number: String): String {
if (!hasPermission(PERMISSION_READ_CONTACTS)) {
return number
}
val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number))
val projection = arrayOf(
PhoneLookup.DISPLAY_NAME
@ -453,6 +457,10 @@ fun Context.getNameFromPhoneNumber(number: String): String {
}
fun Context.getPhotoUriFromPhoneNumber(number: String): String {
if (!hasPermission(PERMISSION_READ_CONTACTS)) {
return ""
}
val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number))
val projection = arrayOf(
PhoneLookup.PHOTO_URI