Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet92/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   88   89   90   91   92   93   94   95   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

100
CHAPTER 6: Content Providers

querySearchDocuments(rootId: String, query: String, projection: 
Array): Cursor:
This is supposed to return documents that match the given query under 
the requested root. The returned documents should be sorted by relevance 
in descending order. For slow queries, you can return data in part and set 
EXTRA_LOADING on the cursor to indicate that you are fetching additional 
data. Then, when the data is available, you can send a change notification 
to trigger a requery and return the complete contents. To support change 
notifications, you must use setNotificationUri(ContentResolver, Uri) 
with a relevant Uri, maybe from buildSearchDocumentsUri(String,
String, String). Then you can call the method notifyChange(Uri, 
android.database.ContentObserver, boolean) with that Uri to send 
change notifications.
Once your documents provider is configured and running, a client component can then use 
an ACTION_OPEN_DOCUMENT or ACTION_CREATE_DOCUMENT intent to open or create a document. 
The Android system picker will be taking care of presenting the appropriate documents to 
the user; you don’t have to provide an own GUI for your documents provider.
Here’s an example of such a client access:
// An integer you can use to identify that call when the
// called Intent returns
val READ_REQUEST_CODE = 42
// ACTION_OPEN_DOCUMENT used in this example is the
// intent to choose a document like for example a file
// file via the system's file browser.
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
// Filter to only show results that can be "opened", such
// as a file (as opposed to a list of informational items
)
intent.addCategory(Intent.CATEGORY_OPENABLE)
// You can use a filter to for example show only images.
// To search for all documents instead, you can use "*/*"
// here.
intent.type = "image/*"
// The actual Intent call - the system will provide the
// GUI
startActivityForResult(intent, READ_REQUEST_CODE)
Once an item is selected from inside the system picker, to catch the intent return you’d write 
something like this:
override fun onActivityResult(requestCode:Int,
resultCode:Int,
resultData:Intent) {



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   88   89   90   91   92   93   94   95   ...   223




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