Get contact name given a phone number in Android

前端 未结 4 418
礼貌的吻别
礼貌的吻别 2020-12-05 12:16

I am trying to retrieve contact names given the contact phone number. I made a function that should work in all API versions, by I can\'t make it work in 1.6 and I can\'t se

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 12:38

     private String getContactNameFromNumber(String number) { 
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    
    
    Cursor cursor = context.getContentResolver().query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null,null,null);
    if (cursor.moveToFirst())
    {
        name = cursor.getString(cursor.getColumnIndex(PhoneLookup.D
    

提交回复
热议问题