内容提供商的应用程序如何指定客户端应用程序访问访问提供商数据所需的权限? [英] How does Content Provider's application specify permissions that client apps need in order to access the provider's data?

本文介绍了内容提供商的应用程序如何指定客户端应用程序访问访问提供商数据所需的权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

BACKGROUND

我正在阅读有关Android内容提供商的教程.我从本教程中了解到,

I am reading this tutorial on Android Content Providers. I understand from this tutorial that,

为了使其他应用程序访问内容提供者的数据,提供者应用程序必须指定客户端应用程序访问其提供者的数据所需的权限.

In order for other applications to access a Content Provider's data, the provider application must specify the permissions which the client applications need to have to access the its provider's data.

客户端应用程序使用<uses-permission>元素(例如

Client applications specify the permissions they require in their manifest file using the <uses-permission> element, e.g.

<uses-permission android:name="android.permission.READ_USER_DICTIONARY" > <!-- In the client app's manifest -->

然后,APK管理器在用户安装客户端应用程序时要求用户同意这些权限(在客户端应用程序中).

Then the APK manager asks the user's consent on these permissions (in the client app) when the user is installing the client application.

问题

QUESTION

我的问题是,提供程序(应用程序)如何指定其他客户端应用程序必须授予的权限才能使它们访问提供程序的数据?

My question is that how does the provider (app) specify the permissions that other client apps must be granted in order for them to access the provider's data?

开发人员指南中,

查找提供者的读取访问权限的确切名称 您正在使用的名称以及所使用的其他访问权限的名称 ,请查看提供商的文档.

To find the exact name of the read access permission for the provider you're using, as well as the names for other access permissions used by the provider, look in the provider's documentation.

这是在提供者应用程序中指定这些权限的方法吗-在 提供商的文档 中?如果是这样,在哪里找到该文档?在哪里可以找到SearchableDictionary提供程序的文档(在本教程中用作示例),如果我在应用程序中编写了内容提供程序,我应该在哪里提供该文档?

So is that the way to specify those permissions in the provider app - in the provider's documentation? If so, where is that documentation found? Where can I find that documentation for the SearchableDictionary provider (used as an example in the tutorial), and if I write a Content Provider in my app, where shall I provide that documentation?

推荐答案

在提供程序应用的AndroidManifest.xml中定义权限

Define Permission in provider app's AndroidManifest.xml

<permission
    android:name="com.myapp.PERMISSION"/>

在提供者应用的AndroidManifest.xml中定义提供者

Define Provider in provider app's AndroidManifest.xml

<provider
        android:name=".MyProvider"
        android:authorities="com.myapp.MyProvider.AUTHORITY"
        android:enabled="true"
        android:exported="true"
        android:multiprocess="true"
        android:readPermission="com.myapp.PERMISSION" />

客户端的AndroidManifest.xml应该具有uses-permission标签

Client's AndroidManifest.xml should have uses-permission tag

<uses-permission android:name="com.myapp.PERMISSION"/>

然后客户端可以访问提供程序

Then client can access the provider

Cursor cursor = getContentResolver().query(
Uri.parse("content://com.myapp.MyProvider.AUTHORITY/xxx" ),null, null, null, null);

这篇关于内容提供商的应用程序如何指定客户端应用程序访问访问提供商数据所需的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆