这可能是一个简单的问题,但我很难确定一个直接的答案。
我使用 Eclipse Android ADT 在项目中自己单独的包中创建了一个内容提供程序。该包包含在整个项目的 src 中。修改 AndroidManifest.xml 时,我将其作为 > 的子项包含在内:
<provider android:name="JobProvider"
android:authorities="dsndata.sds2Mobile.provider.JobProvider" />
将使用提供程序的代码位于 src 中的单独包中,
其中是存储该提供程序的最佳位置提供商?在与使用它的源相同的包中?另外, android:name 和 android:authorities 的正确值是什么?我确信它们会根据提供程序的存储位置而有所不同。
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 project. 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.
发布评论
评论(2)
您可以将您的提供程序存储在应用程序中的任何位置。这取决于您在 ContentProvider 类中提供的 URI 名称。始终记住应用程序中使用的 URI 名称必须具有唯一的权限和路径。
Android:name 是您的 Content Provider 类名及其包名
Android:authorities 是您的 Provider 可用的 URI 内容名称。
欲了解更多信息,请
http://marakana.com/s/post/1375/android_content_provider_tutorial
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
您可以将提供程序放置在您喜欢的任何位置。如果您正在编写一个为您的应用程序存储数据的提供程序(并且仅适用于您的应用程序,并且只有您的应用程序使用它),那么将应用程序代码放在自己的包中是最干净的。通常,“provider”是包名称。
至于名称和权限,请参见Manifest文档:
内容权限是一个唯一的字符串,用于将 content:// uri(uri 到数据)映射到您的类。 ContentResolver 使用该映射来确定如何将给定请求(通过 URI 标识)提供给正确的类(您的类)。因此需要唯一的字符串。
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:
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.