Android : Check phone number present in Contact List ? (Phone number retrieve from phone call)

前端 未结 4 1491
时光取名叫无心
时光取名叫无心 2021-02-02 14:03

I make a BroadcastReceiver to receive Phone number of the person who call me




        
4条回答
  •  不要未来只要你来
    2021-02-02 14:38

    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()) {
             cur.close();
             return true;
       }
       } finally {
       if (cur != null)
          cur.close();
       }
       return false;
    }
    

提交回复
热议问题