Mark,

The way you're doing this seems waaay too complicated.

The goal is to use common code for the content provider, while being able to switch the authority string and the class name, agreed?

If you are building with ant, there is a task that does string replacements.

If you are using Eclipse / library project, just create a subclass of the common content provider base class in each of the respective application projects. Use this subclass in the manifest, and have it pass the authority string to the base class, where it can be stored in a static, and used by the content provider's clients.

Library:

class CommonContentProviderBase extends ContentProvider {
public static String AUTHORITY = null;

CommonContentProviderBase (String authority) {
AUTHORITY = authority;
}

@Override
public boolean onCreate() {
gUrlMatcher.addURI(AUTHORITY, ... );
...
}
....
}

Use like this:

Uri.ParseUri("content://" + CommonContentProviderBase.AUTHORITY.....)

Lite application:

class LiteProvider extends CommonContentProviderBase {
public LiteProvider() {
super("mark.carter.data.lite");
}
}

<provider name=".LiteProvider" authorities="mark.carter.data.lite"/>

Similar for the pro version.

-- Kostya

14.12.2010 7:17, Mark Carter пишет:
An app cannot be installed if (in a provider Manifest element) it
specifies an authority that has already been specified by an existing
app.

This can lead to problems when installing the pro version of an app
with the lite version already installed.

How do devs deal with this?

My current approach is to always specify an authority using the app
package name as a prefix. This guarantees uniqueness.

Furthermore, I use a meta-data element to specify that the lite/pro
content providers are logically the same.

In the code, I use PackageManager.queryContentProviders() to get the
authority "candidates" (sharing the same meta-data value) and then
choose the most appropriate one to use in a Uri which I can then pass
into ContentResolver.query().

Essentially, I'm using the meta-data element to specify what I would
like to use as an authority, but am prevented from doing so.

This is quite cumbersome, so is there a neater way?



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to