How to use contentresolver
This article mainly shows you "how to use contentresolver", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use contentresolver" this article.
Contentresolver content provider is a tool for Android cross-program data exchange, which provides a complete mechanism. Allow one program to access the data of another program, while ensuring the security of the accessed data, you can choose part of the data to share. This article introduces its basic usage and related matters.
Contentresolver Runtime permission request
Above Android7.0, permissions are divided into normal permissions and dangerous permissions, and dangerous permissions need to be applied dynamically. The application steps are as follows:
Check whether the permission has been obtained by using the checkSelfPermission () method of ContextCompat
If the permission is not obtained, use the requestPerssion () method of ActivityCompat to apply for permission.
Rewrite the onRequestPermissionResult () method to process the application result.
PublicclassContentResolverTestActivityextendsAppCompatActivity {
@ Override
ProtectedvoidonCreate (BundlesavedInstanceState) {
Super.onCreate (savedInstanceState)
SetContentView (R.layout.activity_content_resolver_test)
/ / the first step
If (ContextCompat.checkSelfPermission (this,Manifest.permission.READ_CONTACTS))
! = PackageManager.PERMISSION_GRANTED) {
/ / in the second step, the third parameter can transfer a unique value
ActivityCompat.requestPermissions (this
NewString [] {Manifest.permission.READ_CONTACTS}
1)
} else {
/ / Business logic after obtaining permission
}
}
Contentresolver reads data from other programs
Apply for relevant permissions dynamically
Using the getContentResolver () method of Context to obtain ContentResovler
Execute the query method of ContentResovler to get a Cursor object
Process the obtained Cursor
The above is all the contents of this article "how to use contentresolver". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!