Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet73/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   69   70   71   72   73   74   75   76   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

78
CHAPTER 6: Content Providers

override fun : openTypedAssetFile(uri:Uri, mimeTypeFilter:String, 
opts:Bundle): AssetFileDescriptor
Implement this if you want clients to be able to read (not write!) 
asset data by MIME type. The default implementation compares the 
mimeTypeFilter with whatever it gets from getType(Uri), and if they 
match, it simply forwards to openAssetFile(...).

override fun : openTypedAssetFile(uri:Uri, mimeTypeFilter:String, 
opts:Bundle, signal:CancellationSignal): AssetFileDescriptor
This is the same as openTypedAssetFile(Uri, String, Bundle) but 
allows for cancellation from the client side. The provider can save the 
signal object and catch the client’s cancellation request by periodically 
calling throwIfCancelled() on the signal object.

override fun openPipeHelper(uri: Uri?, mimeType: 
String?, opts: Bundle?, args: T, func: PipeDataWriter?): 
ParcelFileDescriptor
This is a helper function for implementing openTypedAssetFile(Uri, 
String, Bundle). It creates a data pipe and a background thread 
allowing you to stream generated data back to the client. This function 
returns a new ParcelFileDescriptor. After work is done, the caller must 
close it.

override fun openFileHelper(uri:Uri, mode:String): 
ParcelFileDescriptor
This is a convenience method for subclasses. The default implementation 
opens a file whose path is given by the result of a query() method using 
the URI provided. For the file path, the _data member gets extracted 
from the query result, and the result set count must be 1.
Those methods that return a ParcelFileDescriptor object can invoke appropriate 
constructors as follows to build input and output streams for the files:
val fd = ... // get the ParcelFileDescriptor
val inpStream =
ParcelFileDescriptor.AutoCloseInputStream(fd)
val outpStream =
ParcelFileDescriptor.AutoCloseOutputStream(fd)
You must use the close() method on the stream once its work is done. The Auto means the 
ParcelFileDescriptor gets closed for you automatically when you close the streams.
Similarly, those methods that return an AssetFileDescriptor object can invoke appropriate 
constructors as follows to build input and output streams for the files:
val fd = ... // get the AssetFileDescriptor
val inpStream =
AssetFileDescriptor.AutoCloseInputStream(fd)
val outpStream =
AssetFileDescriptor.AutoCloseOutputStream(fd)



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   223




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