Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet66/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   62   63   64   65   66   67   68   69   ...   223
Bog'liq
@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:

"de.pspaeth.crcons.VIEW"/>
"android.intent.category.DEFAULT"/>
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:resource="resource specification"
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.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   62   63   64   65   66   67   68   69   ...   223




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