I\'ve implemented custom ContactsDirectoryProvider which works fine when Contacts or Dialer applications are searching for contacts using URIs of the form content://
A workaround that we are using is to use a BroadcastReceiver to listen to incoming calls:
<receiver android:name=".domain.callerid.CallerIdBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
Then in the onReceive method of the BroadcastReceiver you can get the incoming number:
intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)
(This requires the READ_CALL_LOG permission starting with Android Pie)
Then you can use the incoming number to match a person and show a toast and or notification