當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneLookup._ID屬性代碼示例

本文整理匯總了Java中android.provider.ContactsContract.PhoneLookup._ID屬性的典型用法代碼示例。如果您正苦於以下問題:Java PhoneLookup._ID屬性的具體用法?Java PhoneLookup._ID怎麽用?Java PhoneLookup._ID使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.provider.ContactsContract.PhoneLookup的用法示例。


在下文中一共展示了PhoneLookup._ID屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getContactsWithPush

public Collection<ContactData> getContactsWithPush(Context context) {
  final ContentResolver resolver = context.getContentResolver();
  final String[] inProjection    = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};

  List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
  final Collection<ContactData> lookupData = new ArrayList<>(pushNumbers.size());

  for (String pushNumber : pushNumbers) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
    Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
    try {
      if (lookupCursor != null && lookupCursor.moveToFirst()) {
        final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
        contactData.numbers.add(new NumberData("XecureChat", pushNumber));
        lookupData.add(contactData);
      }
    } finally {
      if (lookupCursor != null)
        lookupCursor.close();
    }
  }
  return lookupData;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:23,代碼來源:ContactAccessor.java

示例2: isSystemContact

public boolean isSystemContact(Context context, String number) {
  Uri      uri        = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
  String[] projection = new String[]{PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY,
                                     PhoneLookup._ID, PhoneLookup.NUMBER};
  Cursor   cursor     = context.getContentResolver().query(uri, projection, null, null, null);

  try {
    if (cursor != null && cursor.moveToFirst()) {
      return true;
    }
  } finally {
    if (cursor != null) cursor.close();
  }

  return false;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:16,代碼來源:ContactAccessor.java

示例3: getContactUriForNumber

private Uri getContactUriForNumber(String number) {
  String[] PROJECTION = new String[] {
    PhoneLookup.DISPLAY_NAME,
    PhoneLookup.LOOKUP_KEY,
    PhoneLookup._ID,
  };

  Uri uri       = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
  Cursor cursor = null;

  try {
    cursor = context.getContentResolver().query(uri, PROJECTION, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }

  return null;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:23,代碼來源:ContactIdentityManagerGingerbread.java

示例4: getSelfIdentityUri

@SuppressLint("NewApi")
@Override
public Uri getSelfIdentityUri() {
  String[] PROJECTION = new String[] {
      PhoneLookup.DISPLAY_NAME,
      PhoneLookup.LOOKUP_KEY,
      PhoneLookup._ID,
  };

  Cursor cursor = null;

  try {
    cursor = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI,
                                                  PROJECTION, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      return Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }

  return null;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:25,代碼來源:ContactIdentityManagerICS.java

示例5: getContactsWithPush

public Collection<ContactData> getContactsWithPush(Context context) {
  final ContentResolver resolver = context.getContentResolver();
  final String[] inProjection    = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};

  List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
  final Collection<ContactData> lookupData = new ArrayList<>(pushNumbers.size());

  for (String pushNumber : pushNumbers) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
    Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
    try {
      if (lookupCursor != null && lookupCursor.moveToFirst()) {
        final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
        contactData.numbers.add(new NumberData("TextSecure", pushNumber));
        lookupData.add(contactData);
      }
    } finally {
      if (lookupCursor != null)
        lookupCursor.close();
    }
  }
  return lookupData;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:23,代碼來源:ContactAccessor.java

示例6: getContactsWithPush

public Collection<ContactData> getContactsWithPush(Context context) {
  final ContentResolver resolver = context.getContentResolver();
  final String[] inProjection    = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};

  List<String> pushNumbers = TextSecureDirectory.getInstance(context).getActiveNumbers();
  final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());

  for (String pushNumber : pushNumbers) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
    Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
    try {
      if (lookupCursor != null && lookupCursor.moveToFirst()) {
        final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
        contactData.numbers.add(new NumberData("TextSecure", pushNumber));
        lookupData.add(contactData);
      }
    } finally {
      if (lookupCursor != null)
        lookupCursor.close();
    }
  }
  return lookupData;
}
 
開發者ID:redcracker,項目名稱:TextSecure,代碼行數:23,代碼來源:ContactAccessor.java

示例7: getContactsWithPush

public Collection<ContactData> getContactsWithPush(Context context) {
  final ContentResolver resolver = context.getContentResolver();
  final String[] inProjection    = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};

  List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers();
  final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());

  for (String pushNumber : pushNumbers) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
    Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
    try {
      if (lookupCursor != null && lookupCursor.moveToFirst()) {
        final ContactData contactData = new ContactData(lookupCursor.getLong(0), lookupCursor.getString(1));
        contactData.numbers.add(new NumberData("TextSecure", pushNumber));
        lookupData.add(contactData);
      }
    } finally {
      if (lookupCursor != null)
        lookupCursor.close();
    }
  }
  return lookupData;
}
 
開發者ID:Securecom,項目名稱:Securecom-Text,代碼行數:23,代碼來源:ContactAccessor.java

示例8: contactExists

public boolean contactExists(Context context, String number) {
	// / number is the phone number
	Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
			Uri.encode(number));
	String[] mPhoneNumberProjection = { PhoneLookup._ID,
			PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
	Cursor cur = context.getContentResolver().query(lookupUri,
			mPhoneNumberProjection, null, null, null);
	try {
		if (cur.moveToFirst()) {
			return true;
		}
	} finally {
		if (cur != null)
			cur.close();
	}
	return false;
}
 
開發者ID:saurabh2590,項目名稱:EasyAccess,代碼行數:18,代碼來源:TextMessagesViewerApp.java

示例9: getId

/**
 * Returns the ID of the number passed as a parameter.
 * 
 * @param contactNumber
 *            The number whose ID is to be returned.
 * @return String The ID of the contact. Returns null if contact is not
 *         saved in the phone.
 */

public String getId(String contactNumber) {
	String contactId = null;
	ContentResolver contentResolver = context.getContentResolver();

	Uri uri = Uri.withAppendedPath(
			ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
			Uri.encode(contactNumber));

	String[] projection = new String[] {
			ContactsContract.Contacts.DISPLAY_NAME, PhoneLookup._ID };

	Cursor cursor = contentResolver
			.query(uri, projection, null, null, null);

	if (cursor != null) {
		while (cursor.moveToNext()) {
			contactId = cursor.getString(cursor
					.getColumnIndexOrThrow(PhoneLookup._ID));
			break;
		}
		cursor.close();
	}
	return contactId;
}
 
開發者ID:saurabh2590,項目名稱:EasyAccess,代碼行數:33,代碼來源:ContactManager.java

示例10: getContactFromPhoneNumber

public static Contact getContactFromPhoneNumber(String phoneNumber, Context context) {
    Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    final String[] contactProjection = new String[] {PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};

    Cursor c = context.getContentResolver().query(contactUri, contactProjection, null, null, null);
    Contact contact = new Contact(phoneNumber, phoneNumber);

    try {
        if (c.moveToFirst()) {
            long id = c.getLong(c.getColumnIndex(PhoneLookup._ID));
            String name = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));

            contact = new Contact(id, phoneNumber, name);
        }
    } catch (Exception e) {
        Log.d(TAG, "Unable to retrieve contact with phone number " + phoneNumber);
    } finally {
        c.close();
    }

    return contact;
}
 
開發者ID:PhoneRemoteControl,項目名稱:OrbitCat,代碼行數:22,代碼來源:ContactUtils.java

示例11: searchContactForPhone

/**
 * <a href="http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html"> PhoneLookup</a>
 *
 * @param context
 * @param phoneNumber
 * @return
 */
public static ContactVo searchContactForPhone(Context context, String phoneNumber) {
    String contactName = null;
    long contactId = -1l;
    if (isPermissionReadContact(context)) {
        Log.d(TAG, String.format("Search Contact Name for Phone [%s]", phoneNumber));
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
        final String[] selection = new String[]{ PhoneLookup._ID, PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME};
        Cursor cur = context.getContentResolver().query(uri, selection, null, null, null);
        try {
            if (cur != null && cur.moveToFirst()) {
                contactId = cur.getLong(cur.getColumnIndexOrThrow(PhoneLookup._ID));
                contactName = cur.getString(cur.getColumnIndex(PhoneLookup.DISPLAY_NAME));
            }
        } finally {
            cur.close();
        }
    }
    Log.d(TAG, String.format("Found Contact %s Name for Phone [%s] : %s", contactId, phoneNumber, contactName));
    ContactVo result = null;
    if (contactId != -1l) {
        result = new ContactVo(contactId, contactName);
    }
    return result;
}
 
開發者ID:gabuzomeu,項目名稱:geoPingProject,代碼行數:31,代碼來源:ContactHelper.java

示例12: isPrioritySender

private static boolean isPrioritySender(int prioritySenders, String number) {
    if (prioritySenders == Policy.PRIORITY_SENDERS_ANY) {
        return true;
    } else {
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
        String[] projection = new String[]{PhoneLookup._ID, PhoneLookup.STARRED};
        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        boolean exists = false;
        int starred = 0;
        try {
            if (cursor != null && cursor.moveToFirst()) {
                exists = true;
                starred = cursor.getInt(cursor.getColumnIndexOrThrow(PhoneLookup.STARRED));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        if (prioritySenders == Policy.PRIORITY_SENDERS_CONTACTS && exists) {
            return true;
        } else if (prioritySenders == Policy.PRIORITY_SENDERS_STARRED && starred == 1) {
            return true;
        }
        return false;
    }
}
 
開發者ID:scifiswapnil,項目名稱:gadgetbridge_artikcloud,代碼行數:27,代碼來源:GBApplication.java

示例13: getUidForSms

private static long getUidForSms(Context context, String number) {
  long uid = -1;
  long contactId = -1;

  ContentResolver contentResolver = context.getContentResolver();
  Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
  String[] projection = new String[] { PhoneLookup._ID };
  Cursor cursor = contentResolver.query(uri, projection, null, null, null);
  if (cursor != null) {
    while (cursor.moveToNext()) {
      contactId = cursor.getLong(cursor.getColumnIndexOrThrow(PhoneLookup._ID));
    }
    cursor.close();
  }

  // second query
  if (contactId != -1) {
    String[] contactProjection = new String[] {
        ContactsContract.Data.RAW_CONTACT_ID
    };
    Cursor contactCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI,
        contactProjection,
        ContactsContract.Data.CONTACT_ID + " = ? ",
        new String[] { contactId + "" },
        null);
    if (contactCursor != null) {
      while (contactCursor.moveToNext()) {
        uid = contactCursor.getLong(contactCursor.getColumnIndexOrThrow(ContactsContract.Data.RAW_CONTACT_ID));
        break;
      }
      contactCursor.close();
    }
  }

  return uid;
}
 
開發者ID:k-kojak,項目名稱:yako,代碼行數:36,代碼來源:Person.java

示例14: get

public ArrayList<Contact> get() {
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] {
            PhoneLookup._ID,
            PhoneLookup.DISPLAY_NAME,
            ContactsContract.CommonDataKinds.Phone.TYPE,
            ContactsContract.CommonDataKinds.Phone.LABEL,
            ContactsContract.CommonDataKinds.Phone.NUMBER
    };
    String[] simTypesQueryParts = new String[simTypes.length];
    Arrays.fill(simTypesQueryParts, ContactsContract.RawContacts.ACCOUNT_TYPE + " <> ?");
    String simTypesQuery = TextUtils.join(" AND ", simTypesQueryParts);
    String selection = ContactsContract.RawContacts.ACCOUNT_TYPE + " IS NULL OR (" + simTypesQuery + ")";
    String[] selectionArgs = simTypes;

    Cursor results = resolver.query(
            uri,
            projection,
            selection,
            selectionArgs,
            null
    );

    // create array of Phone contacts and fill it
    final ArrayList<Contact> phoneContacts = new ArrayList<>();
    int indexId = results.getColumnIndex(PhoneLookup._ID);
    int indexName = results.getColumnIndex(PhoneLookup.DISPLAY_NAME);
    int indexType = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
    int indexLabel = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL);
    int indexNumber = results.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
    while (results.moveToNext()) {
        int type = results.getInt(indexType);
        String custom = results.getString(indexLabel);
        final Contact phoneContact = new Contact(
                results.getString(indexId),
                results.getString(indexName),
                results.getString(indexNumber),
                (String) Phone.getTypeLabel(this.activity.getResources(), type, custom)
        );
        phoneContacts.add(phoneContact);
    }
    results.close();
    return phoneContacts;
}
 
開發者ID:yeriomin,項目名稱:DumbphoneAssistant,代碼行數:44,代碼來源:PhoneUtilEclair.java

示例15: retrieveContactUri

public Uri retrieveContactUri(Contact contact) {
    String lookupKey;
    Long contactId;
    Cursor result = null;
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.RawContacts.CONTACT_ID };
    String selection;
    String[] selectionArgs;

    // at first try to resolve with contacts id
    if (contact.getId() != null) {
        selection = PhoneLookup._ID + "=?";
        selectionArgs = new String[] { contact.getId() };
        result = resolver.query(uri, projection, selection, selectionArgs, null);
        // check if unique result
        if (result.getCount() != 1) {
            result.close();
            result = null;
        }
    }
    
    // if no contact id or no result, try alternate method
    if (result == null) {
        selection = ContactsContract.Contacts.DISPLAY_NAME + " = '?' AND "
                + ContactsContract.CommonDataKinds.Phone.NUMBER + " = '?'"
        ;
        selectionArgs = new String[] { contact.getName(), contact.getNumber() };
        result = resolver.query(uri, projection, selection, selectionArgs, null);
        // check if unique result
        if (result.getCount() != 1) {
            result.close();
            result = null;
        }
    }
            
    // check for result
    if (result == null) {
        return null;
    }
    
    // get results
    result.moveToNext();
    lookupKey = result.getString(0);
    contactId = result.getLong(1);
    result.close();

    // create contact URI
    return ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
}
 
開發者ID:yeriomin,項目名稱:DumbphoneAssistant,代碼行數:49,代碼來源:PhoneUtilEclair.java


注:本文中的android.provider.ContactsContract.PhoneLookup._ID屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。