Skip to content

Instantly share code, notes, and snippets.

@alimashuri
Created October 16, 2018 08:39
Show Gist options
  • Select an option

  • Save alimashuri/05f6fe0938f41aab8cbc68d7b58cdb24 to your computer and use it in GitHub Desktop.

Select an option

Save alimashuri/05f6fe0938f41aab8cbc68d7b58cdb24 to your computer and use it in GitHub Desktop.
/**
* Check if contact is already registered with mimetype
*
* @param resolver content resolver
* @param id user id
* @return boolean
*/
private fun isAlreadyRegisteredMimeType(resolver: ContentResolver, id: String, mimeType: String): Boolean {
var isRegistered = false
val projection = arrayOf(ContactsContract.Data.CONTACT_ID)
val selection = ContactsContract.Data.MIMETYPE + " =? and " + RawContacts.ACCOUNT_TYPE + "=? and " + RawContacts.CONTACT_ID + "=?"
val selectionArgs = arrayOf(
mimeType,
Constants.ACCOUNT_TYPE,
id)
val c = resolver.query(
ContactsContract.Data.CONTENT_URI,
projection,
selection,
selectionArgs,
null)
if (c != null && c?.count > 0) {
isRegistered = true
}
c!!.close()
return isRegistered
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment