Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet85/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   81   82   83   84   85   86   87   88   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

93
CHAPTER 6: Content Providers
cursor.moveToFirst()
while (!cursor.isAfterLast) {
Log.e("LOG", "New entry:")
for(name in cursor.columnNames) {
val v = cursor.getString(
cursor.getColumnIndex(name))
Log.e("LOG"," > " + name + " = " + v)
}
cursor.moveToNext()
}
}
Adding the VoicemailContract.PARAM_KEY_SOURCE_PACKAGE URI parameter is important; 
otherwise, you’ll get a security exception.
Batch-Accessing Content Data
The android.content.ContentProvider class allows your implementation to use the 
following:
applyBatch(
operations: ArrayList):
Array
The default implementation iterates through the list and performs each operation in turn, 
but you can also override the method to use your own logic. The ContentProviderOperation 
objects provided in the parameter describes the operation to perform. It can be one of 
update, delete, and insert.
For your convenience, that class provides a builder, which you can use for example as 
follows:
val oper:ContentProviderOperation =
ContentProviderOperation.newInsert(uri)
.withValue("key1", "val1")
.withValue("key2", 42)
.build()
Securing Content
From the moment you declare a content provider inside AndroidManifest.xml and export 
it by setting its exported attribute to true, other apps are allowed to access the complete 
contents exposed by the provider.
This might not be what you want for sensitive information. As a remedy, to impose 
restrictions on the content or part of the content, you add permission-related attributes to 
the 
 element or its subelements.


94
CHAPTER 6: Content Providers
You basically have the following options:
1. 

Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   81   82   83   84   85   86   87   88   ...   223




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