1

Android can support multiple users on one device.

Is it possible to write an Android app allowing multiple users on one device to read and write data from a shared local database (e.g. SQLite)?

So if user1 writes something to the DB, user2 can view that, and also overwrite it.

Jackson Pauls
  • 225
  • 2
  • 12
  • 1
    If you put this file in a public folder (for example, external storage), you would be able to read and write from it from any number of applications / user spaces. As long as it's not a user-specific storage area, you can do what you want with files. – Ewald Jan 13 '16 at 09:07
  • Extending what Ewald said - putting it in a public folder exposes the file/db to all sorts of manipulation (deletion/edits) that you don't want. – FunkSoulBrother Jan 13 '16 at 09:20
  • 2
    A possibly better approach would be to write a service that would write to the db and be exported as a public service. other apps would be able to use the service to write to the db. – FunkSoulBrother Jan 13 '16 at 09:22
  • 1
    to change db storage location as proposed by @Ewald see http://stackoverflow.com/questions/5332328/sqliteopenhelper-problem-with-fully-qualified-db-path-name – k3b Jan 13 '16 at 09:31
  • @FunkSoulBrother Could you elaborate a little please - what could cause unwanted deletions/edits if I use a public folder? Other installed apps? Anything else? – Jackson Pauls Jan 13 '16 at 10:10
  • Malware in general - viruses, apps that are after your personal information etc. The likelihood of an app writing to the database is not high . I'd say that viruses are more likely to delete the file (which would mean complete data loss). Never place a db or file in a location where it would be exposed. – FunkSoulBrother Jan 13 '16 at 10:54
  • I like the service idea that FunkSoulBrother suggested, it's definitely a cleaner and more robust approach. – Ewald Jan 13 '16 at 11:05
  • @FunkSoulBrother Thanks. The device would generally be used with restricted user profiles, which mitigates that risk somewhat. It looks like I could also use SQLCipher to encrypt the DB. The service idea sounds more complicated, but maybe I'm not understanding it fully. Does it require installing 2 apps? (I only strictly need one.) – Jackson Pauls Jan 13 '16 at 11:12
  • If the users are restricted in what they can install then - yes, the risk would be reduced but still - a user could delete the db by accident or intentionally. Regarding the service - yes, it is a more complex concept but it provides you security because the db will reside in the service's folder and no other app or user would be able to manipulate it. It would require two apps to accomplish this. – FunkSoulBrother Jan 13 '16 at 12:16

1 Answers1

0

Two options:

  1. Use two apps. One app exports access to the DB as a public service. The second app, the one users interact with, calls that service.
  2. Put the DB in a public folder. This may be unsafe.

(Based on comments from @FunkSoulBrother, @Ewald, and @k3b, with thanks.)

Community
  • 1
  • 1
Jackson Pauls
  • 225
  • 2
  • 12