Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet77/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   73   74   75   76   77   78   79   80   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

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)



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   73   74   75   76   77   78   79   80   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling