使用@string为Android:当局ContentProvider的 [英] Using @string for android:authorities in a ContentProvider

查看:145
本文介绍了使用@string为Android:当局ContentProvider的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的清单ContentProvider的,当我完全定义他们很难codeD字符串它的工作原理。例如,

I have a ContentProvider in my manifest, when I define them fully with hardcoded strings it works. E.g.

<provider android:name="com.myprovider" android:authorities="com.myprovider"/>

运行完美,但是ContentProviders是在被使用的多个项目库,而我不希望权限冲突,所以我试图做到以下几点。

Works perfect, however the ContentProviders are in a library that gets used by multiple projects, and I don't want authority conflicts, so I attempted to do the following.

<provider android:name="com.myprovider" android:authorities="@string/myProviderAuthority">

这样,我应该能够确定所有的部门在一个单一的strings.xml文件,并没有应用程序之间的冲突,因为我应该能够使用每个应用程序的资源覆盖系统改变它们。

This way I should be able to define all my authorities in a single strings.xml file and not have conflicts between apps since I should be able to change them using each apps resource override system.

不过,看来,当我尝试建立与@string,它给了我一个畸形的明显错误,并说:供应商不INCUDE(是的,它说INCUDE)当局贡品

However, it appears that when I try to build with @string, it gives me a malformed manifest error and says "Provider does not INCUDE (yes it says INCUDE) authorities tribute"

我无法使用的部门致敬资源字符串,我觉得不舒服,每次我需要保持常量在两个位置。管理局冲突是很难通过我们的QA部门抓了,我不想要的东西不同步,也可能会造成混乱。任何人有,为什么我的code不工作任何想法?

Can I not use a resource string for the authorities tribute, I feel sick everytime I need to maintain constants in two locations. Authority conflicts can be hard to catch by our QA dept, and I don't want things to become out of sync or it could cause confusion. Anybody have any ideas why my code isn't working?

推荐答案

我遇到了类似的问题,但与安卓版本code 属性。当我试图定义版本code。在资源利用对它的引用在清单中的Andr​​oid市场,甚至不准我发布应用程序。这种行为的原因,竟然是相当简单的。资源可以根据当前的配置,并且该值已经是在任何情况下,相同的变化。

I faced a similar problem but with the android:versionCode attribute. When I tried to define the version code in resources and use a reference to it in the manifest Android Market even forbade me to publish the application. The reason of such behavior turned out to be rather simple. Resources can change depending on current configuration and this value have to be the same in any case.

也许,这就是为什么有权威的参考内容提供商不工作过的原因。而在我看来,这不是用这样的参考,因为谁也不能保证会有在一个应用程序的权威资源的唯一价值是一个好主意。据我所知,你可够小心地保持这个资源的一个实例,但没有特殊的编译器或系统检查此,因此它不能被信任。

Probably, this is the reason why content providers with authority references do not work too. And it seems to me that it's not a good idea to use such a reference because there's no guarantee that there will be the only one value for an authority resource in an app. I understand that you can be careful enough to keep a single instance of this resource but there's no special compiler or system checks for this so it cannot be trusted.

这篇关于使用@string为Android:当局ContentProvider的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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