简体   繁体   English

使用内部存储在Android应用程序之间共享大量数据?

[英]Share lots of data between android applications using internal storage?

Background: we are porting an enterprise system to have android clients. 背景:我们正在将企业系统移植为具有android客户端。 The architecture for windows and html is based around a core library that does the hard business logic but no user interaction at all, and we use programs or single page web apps to provide the user interface and simply call the core API library to actually do stuff. Windows和html的体系结构基于一个核心库,该库执行硬业务逻辑,但完全没有用户交互,并且我们使用程序或单页Web应用程序来提供用户界面,只需调用核心API库即可实际完成工作。

The "core" is implemented as a shared library on windows and built into each app. “核心”被实现为Windows上的共享库,并内置到每个应用程序中。 If we mirror this and use a java library, we need to share files using external storage, which is a not permitted as data needs to be reasonably secure. 如果我们对此进行镜像并使用Java库,则需要使用外部存储共享文件,这是不允许的,因为数据需要合理地安全。 (Nb data is binary data, not Sql database, in case that is relevant) (如果相关,Nb数据是二进制数据,而不是Sql数据库)

So we thought about using a bound service, and using intents, content provider etc, but it seems (from googling) we must then distribute the background service separately the user interface app, but this seems terrible experience for new users. 因此,我们考虑过使用绑定服务,并使用意图,内容提供者等,但是似乎(从谷歌搜索出发)然后我们必须分别将后台服务分发到用户界面应用中,但是对于新用户而言,这似乎是糟糕的体验。 However, a bound service seems ideal from all other angles. 但是,从所有其他角度来看,绑定服务似乎都是理想的选择。

We also cannot guarantee which apps a user might download, we will have at least 10 individual apps all doing logically different things, but referencing similar data. 我们也不能保证用户可以下载哪些应用程序,我们将至少有10个单独的应用程序在逻辑上做不同的事情,但是引用相似的数据。

In brief: 简单来说:

  • lots of individual apps all wanting access to same data 很多单独的应用程序都希望访问相同的数据
  • no control over which apps are downloaded 无法控制下载哪些应用程序
  • using external data is not permitted as data should be semi secure 不允许使用外部数据,因为数据应该是半安全的
  • using sqllite might not work as data is long binary chunks ( eg 3Mb plus ). 使用sqllite可能无法正常工作,因为数据是长二进制块(例如3Mb plus)。 (Ref: How to share data across a group of applications in Android ) (参考: 如何在Android中的一组应用程序之间共享数据
  • some data files are big and do not want every app to download a private copy 一些数据文件很大,不希望每个应用程序都下载一个私有副本
  • some data changes dynamically, say every 15min 每隔15分钟就会动态更改一些数据
  • core business logic is big and complex, cannot be distributed in source form, lib/jar ok though. 核心业务逻辑既庞大又复杂,不能以源代码形式分发,但是可以通过lib / jar来分发。
  • the windows solutions all use network IO to an application server, but we want to avoid as much network traffic as possible by storing data locally. Windows解决方案都使用网络IO到应用程序服务器,但是我们希望通过在本地存储数据来避免尽可能多的网络流量。

How can we bundle a bound service in each and every user interface app we distribute? 我们如何在我们分发的每个用户界面应用程序中捆绑绑定服务? Or is there a different way to approach this whole design? 还是有其他方法可以处理整个设计?

I think that there is a few number of options that you can explore: 我认为您可以探索几种选择:

1) I never have done this before though this seems possible as Android is package based. 1)我以前从未做过此事,尽管这似乎是可能的,因为Android是基于软件包的。 First you need to use the same main package across all your apps though each app must be in a separated sub package, eg : main -> au.com.myapp.main and the app actually have it's first screen on app1 -> au.com.myapp.main.app1 . 首先,您需要在所有应用程序中使用相同的主程序包,尽管每个应用程序必须位于单独的子程序包中,例如: main- > au.com.myapp.main,而该应用程序实际上在app1- > au上具有它的第一个屏幕。 com.myapp.main.app1 Create on your main app a method(s) that will look for those extra packages (within your project), as it find something you create a trigger that will display a item on the menu. 在您的主应用程序上创建一个方法(一个或多个),该方法将查找那些额外的程序包(在您的项目内),因为它会找到您创建的触发器,该触发器将在菜单上显示一个项目。 Each app should have the same main packages and main activity, as it will be responsible for enable the user have access to the others and all of them can share the same preferences, files folders and Database. 每个应用程序都应具有相同的主程序包和主要活动,因为它将负责使用户能够访问其他应用程序,并且所有应用程序都可以共享相同的首选项,文件夹和数据库。 When installing the same packages should be overrides though those different ones should keep intact. 当安装相同的软件包时,尽管那些不同的软件包应保持原样,但应优先考虑。 You should have all the 'main' classes for each app, not the real main one declared on your manifest (that will be quite big depending on the amount of activities in all your apps) with those packages. 对于这些应用程序,您应该拥有所有“主要”类,而不是在清单上声明的真正主要类(取决于所有应用程序中的活动量,这会很大)。

2) You can using Spongy Castle, create a shared zone (folder) where you create the DB and write your settings or files, encrypting everything with a key (strong one or using RSA) that might be made by the user or provided once for your company at the very first run. 2)您可以使用Spongy Castle,创建一个共享区域(文件夹),在其中创建数据库并写入设置或文件,使用用户可能制作或针对以下内容提供的密钥(强密钥或使用RSA)加密所有内容您的公司在第一次运行时。 You must decide how to handle this. 您必须决定如何处理。

3) You also can use the share id in all your apps and each app before run perform look up for all packages (it's possible to do) to know and if and what packages exist to check if there is a DB with data in that package. 3)您还可以在所有应用程序和每个应用程序中使用共享ID,然后在运行执行前查找所有包(可以)以了解是否存在以及哪些包存在,以检查该包中是否有包含数据的数据库。

4) Not really nice though create a background service that keep updated all tables in all apps (sharing id or using content provider), you can user AlarmManager to trigger it in intervals rather keep it on at all times and you have all apps. 4)虽然创建一个后台服务来保持所有应用程序中所有表的更新(共享ID或使用内容提供程序),但并不是很好,您可以使用AlarmManager定期触发它,而始终保持打开状态,并且拥有所有应用程序。

My last project had a similar requirement though as the user had to login to do anything, I opted for the option 3 and each data pertinent exclusively to each app went the app DB. 我的上一个项目有一个类似的要求,尽管用户必须登录才能执行任何操作,所以我选择了选项3,并且与每个应用程序相关的每个数据都进入了应用程序数据库。 I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM