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

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

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




        
4条回答
  •  走了就别回头了
    2021-02-02 14:25

    for 1 you should have a look at the recommended ContactsContract.PhoneLookup provider

    A table that represents the result of looking up a phone number, for example for caller ID. To perform a lookup you must append the number you want to find to CONTENT_FILTER_URI. This query is highly optimized.

    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    Cursor mycursor=resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
    if (mycursor!=null && mycursor.moveToFirst()) {
    // record exists
    }
    

    for 2 you can use the context from the onReceive method to call methods that belong to Context

    ContentResolver cr=context.getContentResolver();
    

提交回复
热议问题