public
class
BlockedNumberContract
extends Object
java.lang.Object | |
↳ | android.provider.BlockedNumberContract |
The contract between the blockednumber provider and applications. Contains definitions for the supported URIs and columns.
The content provider exposes a table containing blocked numbers. The columns and URIs for
accessing this table are defined by the BlockedNumberContract.BlockedNumbers
class. Messages, and calls from
blocked numbers are discarded by the platform. Notifications upon provider changes can be
received using a ContentObserver
.
The platform will not block messages, and calls from emergency numbers as defined by
isEmergencyNumber(String)
. If the user contacts
emergency services, number blocking is disabled by the platform for a duration defined by
KEY_DURATION_BLOCKING_DISABLED_AFTER_EMERGENCY_INT
.
Only the system, the default SMS application, and the default phone app
(See getDefaultDialerPackage()
), and carrier apps
(See CarrierService
) can read, and write to the blockednumber
provider. However, canCurrentUserBlockNumbers(Context)
can be accessed by any
application.
Other than regular phone numbers, the blocked number provider can also store addresses (such
as email) from which a user can receive messages, and calls. The blocked numbers are stored
in the COLUMN_ORIGINAL_NUMBER
column. A normalized version of phone
numbers (if normalization is possible) is stored in COLUMN_E164_NUMBER
column. The platform blocks calls, and messages from an address if it is present in in the
COLUMN_ORIGINAL_NUMBER
column or if the E164 version of the address
matches the COLUMN_E164_NUMBER
column.
COLUMN_ORIGINAL_NUMBER
is a required column that needs to be populated.
Apps can optionally provide the COLUMN_E164_NUMBER
which is the phone
number's E164 representation. The provider automatically populates this column if the app does
not provide it. Note that this column is not populated if normalization fails or if the address
is not a phone number (eg: email).
Attempting to insert an existing blocked number (same
COLUMN_ORIGINAL_NUMBER
column) will result in replacing the existing
blocked number.
Examples:
ContentValues values = new ContentValues(); values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "1234567890"); Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values);
ContentValues values = new ContentValues(); values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "1234567890"); values.put(BlockedNumbers.COLUMN_E164_NUMBER, "+11234567890"); Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values);
ContentValues values = new ContentValues(); values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "12345@abdcde.com"); Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values);
Updates are not supported. Use Delete, and Insert instead.
Deletions can be performed as follows:
ContentValues values = new ContentValues(); values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, "1234567890"); Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values); getContentResolver().delete(uri, null, null);To check if a particular number is blocked, use the method
isBlocked(Context, String)
.
All blocked numbers can be enumerated as follows:
Cursor c = getContentResolver().query(BlockedNumbers.CONTENT_URI, new String[]{BlockedNumbers.COLUMN_ID, BlockedNumbers.COLUMN_ORIGINAL_NUMBER, BlockedNumbers.COLUMN_E164_NUMBER}, null, null, null);
Use the method unblock(Context, String)
to unblock numbers.
Apps must use the method canCurrentUserBlockNumbers(Context)
before performing any
operation on the blocked number provider. If canCurrentUserBlockNumbers(Context)
returns
false
, all operations on the provider will fail with a SecurityException
. The
platform will block calls, and messages from numbers in the provider independent of the current
user.