Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("finally")
- public static boolean isContact(String num, ContentResolver contentResolver) {
- /**
- * LGPL - Credit by: ehooo
- * More info in: rollanwar.net
- * Dado un numero de telefono num, retorna si está o no en la agenda
- * Para poder acceder a estos datos es necesario tener permiso de leectura de contactos.
- * ("android.permission.READ_CONTACTS" en AndroidManifest.xml)
- * @param num Numero de telefono
- * @param context Contexto con permisos de leectura de Contactos
- */
- boolean ret = false;
- try{
- Cursor cur = contentResolver.query(Contacts.Phones.CONTENT_URI, null, null, null, null);
- int index = cur.getColumnIndex(Contacts.Phones.NUMBER);
- while (!ret && cur.moveToNext())
- if (num.equals(cur.getString(index)))
- ret = true;
- cur.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement