Pro Android with Kotlin
CHAPTER 6: Content Providers
Download 5.42 Mb. Pdf ko'rish
|
@de android telegram Pro Android with Kotlin Developing Modern Mobile
69
CHAPTER 6: Content Providers If you use grantUriPermissions to temporarily give the URI permissions to components from other apps called by an implicit intent, you have to carefully tailor such an intent. First add the flag Intent.FLAG_GRANT_READ_URI_PERMISSION, and then add the URI you want to allow access for inside the intent’s data field. Here’s an example: intent.action = "com.example.app.VIEW" // SET INTENT ACTION intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // GRANT TEMPORARY READ PERMISSION intent.data = Uri.parse("content:// ") // USE YOUR OWN! startActivity(intent) Inside the intent filter of the called component, you then must specify a element, and it must contain an appropriate URI and a MIME type. The reason why a MIME type must be specified, although we didn’t explicitly state one, is that the Android OS uses the content provider’s getType(Uri) method to automatically add the MIME type while the intent gets resolved. Here’s an example: android:scheme="content" android:host="*" android:pathPattern=".*"/> The called component is then granted access to this URI in the specified way. After it finishes its work, it is supposed to call revokeUriPermission(String, Uri, Int) to revoke the temporary permission it had been given. revokePermission(getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION) Inside the element, there are a couple of child elements you can add, listed here: meta-data: android:value="string" /> This is where either resource or value must be specified. If you use resource, a resource ID such as @string/someString will assign the resource ID itself to the meta-entry, while using value and @string/someString will assign the contents of the resource to the meta-entry. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling