开发者

Where is a content provider stored in an Android project?

This might be a simple question, but I've had a hard time pinning down a direct answer.

I have created a content provider in its own separate package in a project using the Eclipse Android ADT. This package is included in the src of the overall pr开发者_开发技巧oject. When modifying AndroidManifest.xml I included this as a child of <application>:

 <provider android:name="JobProvider"
      android:authorities="dsndata.sds2Mobile.provider.JobProvider" />

The code that will be using the provider is in a separate package also in src

Where would be the best place to store the provider? In the same package as the source using it? Also, What are the correct values for android:name and android:authorities? I'm sure they vary depending on where the provider is stored.


You can place the provider wherever you like. If you are writing a provider that stores data for your app (and only for your app, and only your app uses it) then it's cleanest to just be right in with the app code in its own package. Typically, 'provider' is the package name.

As for the name and authority, see the Manifest documentation:

android:name The name of the class that implements the content provider, a subclass of ContentProvider. This should be a fully qualified class name (such as, "com.example.project.TransportationProvider"). However, as a shorthand, if the first character of the name is a period, it is appended to the package name specified in the element. There is no default. The name must be specified.

android:authorities A list of one or more URI authorities that identify data under the purview of the content provider. Multiple authorities are listed by separating their names with a semicolon. To avoid conflicts, authority names should use a Java-style naming convention (such as com.example.provider.cartoonprovider). Typically, it's the name of the ContentProvider subclass. There is no default. At least one authority must be specified.

The content authority is a unique string that is used to map content:// uris (uri to data) to your class. ContentResolver uses that mapping to identify how to serve a given request, which is identified with a URI, to the correct class (yours). Hence the requirements for a unique string.


you can Store your provider any place in your application.it depends upon whats your URI name provide in ContentProvider class.Always remember the URI name use in your Application must have unique authority and Path.

Android:name is your Content Provider class name with its package name and Android:authorities is your URI content name where your Provider is available. for more information you http://marakana.com/s/post/1375/android_content_provider_tutorial

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜