82
CHAPTER 6: Content Providers
openInputStream(uri: Uri): InputStream
This opens an input stream.
openOutputStream(uri: Uri, mode: String): OutputStream
This opens an output stream.
openOutputStream(uri: Uri): OutputStream
This opens an output stream, in w mode.
The open*Descriptor() methods again closely relate to the corresponding ContentProvider
methods from the “Providing Content” section. The two others, openInputStream() and
openOutputStream(), are convenience methods to more readily access file (stream) data.
To register content observers for asynchronously being signaled when content changes, as
covered earlier, use one of these:
registerContentObserver(uri: Uri, notifyForDescendants: Boolean,
observer: ContentObserver)
unregisterContentObserver(observer: ContentObserver)
To use a content provider that exhibits an extension by virtue of an implementation of its
call() method, you use the corresponding call() method of the content resolver
call(uri: Uri, method: String, arg: String, extras: Bundle)
Accessing System Content Providers
The Android OS and its preinstalled apps provide several content provider components.
Inside the online API documentation, you can find the content provider contract classes in
the “android.provider/Classes” section. The following sections summarize what they are and
how they can be accessed.
BlockedNumberContract
This exposes a table containing blocked numbers. Only the system, the default
phone app, the default SMS app, and carrier apps can access this table, except for
canCurrentUserBlockNumbers(), which can be called by any app. To use it, you, for example,
write this:
val values = ContentValues()
values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER,
"1234567890")
Uri uri = contentResolver.insert(
BlockedNumbers.CONTENT_URI, values)
Do'stlaringiz bilan baham: |