Advertisement
Guest User

is this numbre in my agent (Android)

a guest
Jun 15th, 2010
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. @SuppressWarnings("finally")
  2. public static boolean isContact(String num, ContentResolver contentResolver) {
  3.     /**
  4.      * LGPL - Credit by: ehooo
  5.      * More info in: rollanwar.net
  6.      * Dado un numero de telefono num, retorna si está o no en la agenda
  7.      * Para poder acceder a estos datos es necesario tener permiso de leectura de contactos.
  8.      * ("android.permission.READ_CONTACTS" en AndroidManifest.xml)
  9.      * @param num Numero de telefono
  10.      * @param context Contexto con permisos de leectura de Contactos
  11.      */
  12.     boolean ret = false;
  13.     try{
  14.         Cursor cur = contentResolver.query(Contacts.Phones.CONTENT_URI, null, null, null, null);
  15.         int index = cur.getColumnIndex(Contacts.Phones.NUMBER);
  16.         while (!ret && cur.moveToNext())
  17.             if (num.equals(cur.getString(index)))
  18.                 ret = true;
  19.         cur.close();
  20.     } catch (Exception e) {
  21.         e.printStackTrace();
  22.     } finally {
  23.         return ret;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement