We\'re trying to publish a pay ad-free version of a casual app that\'s currently published free with ads. We refactored all package names to com.mycompanyname.appname.
Lets say your
library package is com.android.app.library
free package is com.android.app.free
paid package is com.android.app.paid
In your free project and paid project, make an identical file in a package which can be anything, but must be the same.
Example:
Create a new package in your free version with com.android.app.data
Create a file called Authority.java and inside (Authority.java) put:
public class Authority {
`public static final String CONTENT_AUTHORITY = "YOUR PROVIDER";`
}
Repeat this for the paid version, remember to keep the package name the same and class name.
Now, in your contract file, in your library use the following:
public static String AUTHORITY = initAuthority();
private static String initAuthority() {
String authority = "something.went.wrong.if.this.is.used";
try {
ClassLoader loader = Contract.class.getClassLoader();
Class> clz = loader.loadClass("com.android.app.data.Authority");
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;
}
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
Now you should be able to use two authorities.
Credit: Ian Warick Android - Having Provider authority in the app project