A new feature introduced in Android Nougat (API 24) is the ability to handle blocking phone numbers at the OS level. This provides a consistent experience for the user across multiple devices with the following:
- Blocked Numbers block both incoming calls and text messages
- Blocked Numbers can be backed up using the Backup & Restore feature
- All apps on the device share the same Blocked Numbers list
In this recipe, we will look at the code to add a number to block, remove the number, and how to check whether the number is already blocked.
Create a new project in Android Studio and call it BlockedCallList
. In the Target Android Devices
dialog, select the Phone & Tablet
option and choose API 24: Android 7.0 Nougat
(or higher) for the Minimum SDK. Select Empty Activity
in the Add an Activity
to Mobile
dialog.