请求从我自己的ContentProvider读权限的另一个应用程序 [英] Requesting read permission from my own ContentProvider in another app

查看:675
本文介绍了请求从我自己的ContentProvider读权限的另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序,我有以下内容提供商在我AndroidManifest声明:

In one app, I have the following content provider declared in my AndroidManifest:

    <provider android:name="bbct.android.common.BaseballCardProvider"
              android:label="@string/provider_name"
              android:authorities="bbct.android.baseballcard"
              android:readPermission="bbct.android.lite.permission.READ"
    />

和其他应用程序请求允许使用它:

And another app requests permission to use it:

<uses-permission android:name="bbct.android.lite.permission.READ" />

但是,当运行这个code:

But when run this code:

    ContentResolver resolver = this.context.getContentResolver();
    Cursor results = resolver.query(BaseballCardContract.CONTENT_URI, BaseballCardContract.PROJECTION, null, null, null);

我收到以下错误信息:

I get the following error message:

E / DatabaseUtils(1009):java.lang.SecurityException异常:权限拒绝:阅读bbct.android.common.BaseballCardProvider URI内容:由PI​​D = 996 //bbct.android.baseballcard/baseball_cards,UID = 10046要求BBCT。 android.lite.permission.READ,或grantUriPermission()

E/DatabaseUtils( 1009): java.lang.SecurityException: Permission Denial: reading bbct.android.common.BaseballCardProvider uri content://bbct.android.baseballcard/baseball_cards from pid=996, uid=10046 requires bbct.android.lite.permission.READ, or grantUriPermission()

从我可以告诉,我请求所需的权限。我缺少的是在这里吗?做些什么我需要看看?

From what I can tell, I am requesting the required permission. What am I missing here? What else do I need to look at?

推荐答案

在应用程序定义你的ContentProvider,你也(在你的其他应用程序)定义你需要/请求的权限?像这样(根内&LT;清单/&GT; 标记):

In the app defining your ContentProvider, did you also define the permission you are requiring/requesting(in your other app)? Like so (within the root <manifest/> tag):

<permission android:name="bbct.android.lite.permission.READ" />

在一般情况下,你需要:

In general, you need to:


  1. 在您应用的清单文件中的一个定义权限

  2. 要求在任何您应用的清单文件的权限,对于希望获得许可的应用

  3. 要求你希望拥有此权限的防范,如活动,服务,或ContentProviders此权限的任何组件(读,写,两者具体分的URI等)

编辑:所以才要100%的清楚,这是不够的,含蓄,要求它,比方说,你的ContentProvider定义的权限。你必须在你的应用程序的清单文件中明确定义它(&LT内;清单/&GT; 标记)。

so just to be 100% clear, it is NOT enough to "implicitly" define a permission by requiring it in, say, your ContentProvider. You have to define it explicitly in your app's manifest file (within the <manifest/> tag).

这篇关于请求从我自己的ContentProvider读权限的另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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