androidandroid-contentproviderauthority

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):

  1. https://stackoverflow.com/search?q=content+provider+authority
  2. Content Providers, Authority and and URI matching
  3. Get a list of available Content Providers
  4. http://developer.android.com/guide/topics/manifest/provider-element.html
  5. http://developer.android.com/guide/topics/providers/content-provider-creating.html

Solution

  • 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:

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

    It works similar to domains in http urls:

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