I know that this is an old topic, but today I encountered this problem, and we are developing for quite some time, therefore we were not ready to go through all the statics in the Content Provider Contract and change them, also because our content provider and database generated a Mechanoid plug-in for Eclipse (Yes, I am also an author! :))
The solution I came across was to add a static initializer to our generated contract, which uses reflection to find the class and uses the static field CONTENT_AUTHORITY if it exists, if it does not return to default:
public class QuxContract { public static final String CONTENT_AUTHORITY = initAuthority(); private static String initAuthority() { String authority = "com.example.app.data.qux"; try { ClassLoader loader = QuxContract.class.getClassLoader(); Class<?> clz = loader.loadClass("com.example.app.data.QuxContentProviderAuthority"); Field declaredField = clz.getDeclaredField("CONTENT_AUTHORITY"); authority = declaredField.get(null).toString(); } catch (ClassNotFoundException e) {} catch (NoSuchFieldException e) {} catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } return authority; } private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
Now, in each project that refers to the library project, its own privileges can be granted:
package com.example.app.data; public class QuxContentProviderAuthority { public static final String CONTENT_AUTHORITY = "com.example.app.data.baz"; }
Also, be sure to also change the credentials in the manifest.
Ian Warwick Jan 29 '13 at 20:56 2013-01-29 20:56
source share