java - 在另一个应用程序中集成具有自己的数据库的我的模块

标签 java android aar

我有一个包含数据库的 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/

相关文章:

java - Spring hibernate 锁是否适用于不同机器上的其他线程?

java - 检查路径是否代表文件或文件夹

android - 使用 aar 库导致在 Gradle 4.x 中使用 api 缺少依赖项

android - 在 Unity android 应用程序中,如何从引用的 android 库的服务接收内容

java - 在 Kotlin 中开发的 Android 库模块在 Java 应用程序中引用,获取 : Lkotlin/jvm/internal/Intrinsics exception

java - 我如何在java中找到用户位置

java - 按 Enter 键后 Eclipse 向导关闭

Java 垃圾收集监控

java - 视频连续播放 firebase

javascript - Android 开发 - 要引用一个字段,是否需要使用 "this"?