简体   繁体   English

android内容提供商AUTHORITIES

[英]android content provider AUTHORITIES

What is the reason for content provider authorities? 内容提供商当局的原因是什么?

How/why do I want to use them other than I HAVE to declare them in the manifest? 除了我必须在清单中声明它们之外,我是如何/为什么要使用它们?

I've tried to do my homework on this question and cannot find a decent, cohesive discussion on this topic. 我试图在这个问题上做作业,但却找不到关于这个主题的体面,有凝聚力的讨论。 Here is the best I could find (in additi on to the four books on Android development I own): 这是我能找到的最好的(除了我自己的Android开发的四本书):

  1. https://stackoverflow.com/search?q=content+provider+authority https://stackoverflow.com/search?q=content+provider+authority
  2. Content Providers, Authority and and URI matching 内容提供者,权限和URI匹配
  3. Get a list of available Content Providers 获取可用内容提供商列表
  4. http://developer.android.com/guide/topics/manifest/provider-element.html http://developer.android.com/guide/topics/manifest/provider-element.html
  5. http://developer.android.com/guide/topics/providers/content-provider-creating.html http://developer.android.com/guide/topics/providers/content-provider-creating.html

The Authority is used to interact with a particular content provider, that means it must be unique. 管理局用于与特定内容提供商进行交互,这意味着它必须是唯一的。 That's why is a good practice to declare it as your domain name (in reverse) plus the name of the package containing the provider, that way is less likely that other developer creates an app with a content provider declaring the same authority. 这就是为什么是一个很好的做法 ,以声明为您的域名(反向),加上包含提供的包的名称,这种方式是不太可能的其他开发人员创建与内容提供商,宣布相同的权限的应用程序。

You declare it in the manifest so your app and other apps (if you let them) can manipulate data through your content provider in the form of a uri: 您在清单中声明它,以便您的应用程序和其他应用程序(如果您允许)可以通过您的内容提供商以uri的形式操作数据:

content://authority-name/data-in-the-provider

It works similar to domains in http urls: 它的工作方式类似于http urls中的域:

http://domain-name/data-in-the-site

I am also looking for explanation and to add to answer provided by ILovemyPoncho, I hit this particular answer and I quote: 我也在寻找解释,并添加到ILovemyPoncho提供的答案,我点击这个特定的答案 ,我引用:

and what exactly is android:authorities asking for? 什么是android:当局要求的是什么?

A system wide unique identifier for your provider. 您的提供商的系统范围唯一标识符。 Or better worldwide unique. 或者更好的全球独特。 All providers are registered with the system and they need to be unique or the second app that wants to use the same name can't be installed. 所有提供程序都在系统中注册,它们必须是唯一的,否则无法安装想要使用相同名称的第二个应用程序。

You use that string in the end to communicate with your provider via an Uri like 您最后使用该字符串通过Uri与您的提供商进行通信

Uri uri = Uri.parse("content://" + "your.authoritiy.string") Uri uri = Uri.parse(“content://”+“your.authoritiy.string”)

Let's put it this way: There is an invisible hand that facilitates your request to your app's ContentProvider. 让我们这样说:有一只看不见的手可以方便您对应用的ContentProvider的请求。

For example: 例如:

    Uri uri = mContext.getContentResolver().insert(NotifireContentProvider2.NOTE_URI, values);

Basically, what you are saying here to the Android OS is insert data given the URI containing the authority you have defined in the XML. 基本上,您在Android操作系统中所说的是插入数据,给定URI包含您在XML中定义的权限。 The OS will search for this particular content provider and send the request to it. 操作系统将搜索此特定内容提供商并将请求发送给它。 You insert method on the ContentProvider will be called and you must match the URI to handle it accordingly. 您将调用ContentProvider上的insert方法,并且必须匹配URI以相应地处理它。

Also, what if, you're content provider is so simplistic that others have similar authority as well. 此外,如果您是内容提供商是如此简单,以至于其他人也拥有类似的权限。 I haven't encountered those two problem I mentioned but I reckon it won't be pleasant. 我没有遇到过我提到的那两个问题,但我认为这不会令人愉快。

Authority is there to make sure that the OS understand which provider will provide the data to the requesting app and to make sure that is the provider providing it. 权限是为了确保操作系统了解哪个提供商将向请求的应用程序提供数据,并确保提供它的提供商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM