Module with ContentProvider

自作多情 提交于 2020-01-06 20:01:32

问题


I'm ussing this library, the problem starts with:

Tray is based on a ContentProvider. A ContentProvider needs a unique authority. When you use the same authority for multiple apps you will be unable to install the app due to a authority conflict with the error message:

Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]

because i didn't read this before, i used this library to fix problems with multi thread SharedPreference, this project had to become in a module to use in multiple projects.

At the moment of installing every App with this Module, throws the Failure [INSTALL_FAILED_CONFLICTING_PROVIDER] exception.

Because authority is already used in the first installed app.


The questions are:

  • How can i skip installation of Module that is already installed? (Installing the rest of the app, so error will disapear)

  • else, How can i structure the projects? to be able to install multiple apps built with the Module that have the ContentProvider Library.



回答1:


Fixed

For those that need something similar these are the steps to follow:

Step 1. I configured Tray Library in a Main Project "required for the rest of apps" (the app that hosts database preferences)

Step 2. I extracted from repository the required classes to connect with the Tray ContentProvider, which are:

  • AbstractTrayPreference.java
  • ContentProviderStorage.java
  • ItemNotFoundException.java
  • Migration.java
  • OnTrayPreferenceChangeListener.java
  • PreferenceAccessor.java
  • Preferences.java
  • PreferenceStorage.java
  • SqliteHelper.java
  • TrayContract.java
  • TrayDBHelper.java
  • TrayException.java
  • TrayItem.java
  • TrayPreferences.java
  • TrayProviderHelper.java
  • TrayRuntimeException.java
  • TrayStorage.java
  • TrayUri.java
  • WrongTypeException.java

in a new package for the common Module.

Step 3. I hardcoded authority name via constant variable:

This must match with Main Project configuration:

// bild.gradle of Main Project
resValue "string", "tray__authority", "<your.app.package>.tray"


// TrayContract.java of Module
@NonNull
private static String getAuthority(@NonNull final Context context) {
    return TextUtils.isEmpty(sTestAuthority) ?
            AppConstant.TRAY_AUTHORITY: // <-- this one = <your.app.package>.tray
            sTestAuthority;
}

Finally I can use the class normally:

// etc
import <your.app.package>.tray.TrayPreferences;
// etc
public class AppPreferencesManager extends TrayPreferences {
// etc
}

it worked :)



来源:https://stackoverflow.com/questions/35510925/module-with-contentprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!