Is there a simple way to check if an incoming caller is a contact in Android?

后端 未结 2 1735
不思量自难忘°
不思量自难忘° 2021-02-09 15:05

When an Android phone receives a call it automatically checks if the call exists in its own contact database. I was wondering if there is a simple way to access that information

2条回答
  •  爱一瞬间的悲伤
    2021-02-09 15:42

    Here is the code for 2.0 and later

        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
        Cursor cursor = resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null);        
    
        if (cursor != null && cursor.moveToFirst()) {
            String name = cursor.getString(0);
            cursor.close();
        } 
    

提交回复
热议问题