(Context context, InternetAddress address)
| 170 | } |
| 171 | |
| 172 | @NonNull |
| 173 | static ShortcutInfoCompat.Builder getShortcut(Context context, InternetAddress address) { |
| 174 | String name = address.getPersonal(); |
| 175 | String email = address.getAddress(); |
| 176 | |
| 177 | Uri lookupUri = null; |
| 178 | boolean contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS); |
| 179 | if (contacts) { |
| 180 | ContentResolver resolver = context.getContentResolver(); |
| 181 | try (Cursor cursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, |
| 182 | new String[]{ |
| 183 | ContactsContract.CommonDataKinds.Photo.CONTACT_ID, |
| 184 | ContactsContract.Contacts.LOOKUP_KEY, |
| 185 | ContactsContract.Contacts.DISPLAY_NAME |
| 186 | }, |
| 187 | ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?", |
| 188 | new String[]{email}, ContactsContract.Contacts.DISPLAY_NAME)) { |
| 189 | if (cursor != null && cursor.moveToNext()) { |
| 190 | int colContactId = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.CONTACT_ID); |
| 191 | int colLookupKey = cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY); |
| 192 | int colDisplayName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); |
| 193 | |
| 194 | long contactId = cursor.getLong(colContactId); |
| 195 | String lookupKey = cursor.getString(colLookupKey); |
| 196 | String displayName = cursor.getString(colDisplayName); |
| 197 | |
| 198 | lookupUri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey); |
| 199 | if (!TextUtils.isEmpty(displayName)) |
| 200 | name = displayName; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return getShortcut(context, email, name, lookupUri); |
| 206 | } |
| 207 | |
| 208 | @NonNull |
| 209 | static ShortcutInfoCompat.Builder getShortcut(Context context, EntityContact contact) { |
no test coverage detected