我有一个包含数据库的 Notes 应用程序,我需要在我的两个父应用程序中将这个 Notes 应用程序用作库或模块,我如何在我的两个应用程序中使用它?
AAR:
如果我使用 .aar 意味着可以在 aar 模块中创建或存储数据库。
子模块:
如果我去子模块,我需要在每个项目中创建表。
个人APP:
如果我选择个人应用程序,我如何共享我的数据库详细信息。
最佳答案
我想,这是您使用 Content Provider 的最佳选择。
However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object. Together, providers and provider clients offer a consistent, standard interface to data that also handles inter-process communication and secure data access.
Typically you work with content providers in one of two scenarios; you may want to implement code to access an existing content provider in another application, or you may want to create a new content provider in your application to share data with other applications.
来源:https://developer.android.com/guide/topics/providers/content-provider-basics
在您的 Notes 应用程序中创建内容提供者后,其他应用程序可以通过内容解析器访问。这与您在 Android 上访问书签或联系人的方式完全相似。
还有一个建议:如果您只想在应用之间共享,请不要忘记注意安全性。
If you are using a content provider for sharing data between only your own apps, it is preferable to use the android:protectionLevel attribute set to signature protection. Signature permissions do not require user confirmation, so they provide a better user experience and more controlled access to the content provider data when the apps accessing the data are signed with the same key.
来源:https://developer.android.com/training/articles/security-tips#ContentProviders
关于java - 在另一个应用程序中集成具有自己的数据库的我的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56684261/