Problem with duplicate Android server

We are trying to publish a free version of a free, free ad with free advertising. We reorganized all the package names to com.mycompanyname.appname.pro , the free one on the market, after all, does not have .pro at the end. We also went to our content provider and changed the permissions to the same as the package name. So the "free version" has

 AUTHORITY = "com.mycompanyname.appname" 

and "the free version for paying for advertising has

 AUTHORITY = "com.mycompanyname.appname.pro" 

but we can’t install both the free and the β€œpro” version on the same device. Whatever the cost, the class name for the provider is the same in both applications.

We cannot install directly from apk, and if we try to download from the Android market, we will get the error message "duplicate provider Authority".

What are we missing? Is there still a place to look for problems, or do we have something fundamentally wrong?

+6
android android-contentprovider google-play
Jun 21 2018-11-11T00:
source share
4 answers

Basically, what I did was create an abstract base class for each of my ContentProviders and inherit from it for every application that I want to do, overriding the permissions path. So in my AbstractContentProvider I have:

 public AbstractContentProvider() { sURIMatcher.addURI(getAuthority(), BASE_PATH, ITEMS); sURIMatcher.addURI(getAuthority(), BASE_PATH + "/#", ITEM_ID); } protected abstract String getAuthority(); 

and then in each subclass I:

 private static final String AUTHORITY = "my.package.app1.ContentProvider"; @Override protected String getAuthority() { return AUTHORITY; } 

In AndroidManifest, I will register them with:

  <provider android:name="my.package.app1.ContentProvider" android:authorities="my.package.app1.ContentProvider"> </provider> 

Now the trick is that I want to access these content providers in a common (library) code that does not know about the specific classes of the application. To do this, I define String in my strings.xml file, which I override for each application. Then I can use:

 Uri.parse(getString(R.string.contentProviderUri)) 

and in every application the correct ContentProvider is used without any conflicts. Thus, basically, using the tuning mechanism for dependency injection.

+2
Oct 18 '12 at 20:44
source share

Let's say your library package com.android.app.library free package com.android.app.free paid package com.android.app.paid

In your free project and paid project, create an identical file in the package, which can be anything, but it must be the same.

Example:

  • Create a new package in your free version using com.android.app.data p>

  • Create a file called Authority.java and inside (Authority.java):

    public class Authority {

     `public static final String CONTENT_AUTHORITY = "YOUR PROVIDER";` 

    }

  • Repeat this for the paid version, do not forget to leave the package name the same and the 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); 

You should now be able to use two organs.

Credit: Jan Varick Android - the presence of supplier authority in the application project

+2
Jan 11 '14 at 11:22
source share

Google by default adds the application measurement provider to your APP, so in the build.gradle file you need to define the applicationID under the tag android tag exaple defaultConfig {a pplicationId "com.example.my.app" minSdkVersion 15 targetSdkVersion 19 versionCode 1 versionName "1.0"}

+2
Feb 10 '16 at 5:33
source share

I encountered the same problem with an error message stating that the provider name is already registered. I thought that the trick could be to use either another authority or a different name, therefore, in my case, expanding my base provider from the library project in both the free and the pro version. This will fix your problem if you are still using it (noticed that it was an old post, but there are no answers, so I decided to post how I got around it).

I was curious that someone else came across the same thing, and, of course, this seems like an error in the Android platform. See problem details here or a similar SO post here .

0
Mar 30 2018-12-14T00:
source share



All Articles