22

Android introduced the Multiple Users feature in 4.2 (Jelly Bean MR1) and its documentation states:

From your app’s point of view, each user is running on a completely separate device.

And here is a quote from the Environment.getExternalsStorageDirectory() and getExternalStoragePublicDirectory() methods doc:

On devices with multiple users (as described by UserManager), each user has their own isolated external storage. Applications only have access to the external storage for the user they're running as.

Could it be true that there really is no reliable way to communicate data between users on a single device without using the network as mediator? I'm looking for solutions that don't rely on quirks of how the device's file system is laid out by a manufacturer. Also, for security, the sharing should be internal to my app.

Even if file sharing is indeed impossible, is communication via intents somehow possible?

There are use cases for this. Use Case 1: let's say I'm writing an input method app that requires a 100MB dictionary file. I'd like to code things so that if User A downloads this file, then User B can access it also without needing to re-download. Use Case 2: let's say I'm writing a fun Leave My Wife a Note app that allows User A to type messages that will appear next time User B logs in (without using the network).

This thread on a separate site proposes a solution, but their method seems undocumented and possibly unreliable. And there are a few other SO questions that have a title similar to this one but are actually discussing different topics.

Community
  • 1
  • 1
Jo Jo
  • 7,245
  • 5
  • 34
  • 49
  • I still have not found a solution to this problem. I tried using /sdcard/Android/obb but it did not work on the Samsung Galaxy Tab 4. – Jo Jo Aug 26 '15 at 03:57

3 Answers3

20

OBB Folder (/sdcard/Android/obb) is used to share files and folder between the multi users. But OBB folder not shown in my second user (One plus 5 mobile). So I have tried to create an OBB folder in Android folder (/sdcard/Android/) in second user and "BOOM" it worked. Now i am able to access the shared files in second user. Try this trick if OBB folder not shown in your second user.

Prasaathviki
  • 1,147
  • 2
  • 11
  • 22
  • 1
    Thanks. This was an important step missing from the other (higher rated) answer. As soon as I created an obb folder for the second user too, it showed the internal files and folders. – Piyush Soni Mar 12 '18 at 12:16
12

OBB files (stored in /sdcard/Android/obb) and used as expansion files in Google Play are shared between all users by design, as they are fairly large. If you Input method uses expansion files, the downloaded data will be shared automatically. You can send broadcasts to other users but that requires the INTERACT_ACROSS_USERS permission, which is reserved for system applications.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • Good info, Nikolay. I wonder if the path you mentioned is officially supported or has documentation. Also I've upvoted your answer, but haven't accepted it yet because ideally the shared area would be inaccessible to other apps. I'm starting to think there really is no solution that fits my exact requirements. – Jo Jo Feb 20 '14 at 14:28
  • Paths are usually considered implementation details, and change from version to version, so they are usually not documented in detail. See the JavaDoc of `StorageManager` for some official info on this: http://developer.android.com/reference/android/os/storage/StorageManager.html – Nikolay Elenkov Feb 20 '14 at 14:32
  • This does not work on my Nexus 5X with v7.1.1. The _obb_ folder is not there (or not visible). – David Balažic Mar 15 '17 at 23:01
  • Worked on Android P. However, I had to prime it by installing and using an app that used obb on both accounts, such as Ikea Place... Only then did the obb folder show up – Ray Foss Sep 02 '18 at 22:34
  • 2
    As of Android Q, there is no way to make it work. I spent an hour trying everything – Ray Foss Jul 25 '20 at 06:34
2

I also had the same question, and have tried various approaches such as using /sdcard/Android/obb but it does not work in Android 10. So I followed below approach, and I am able to copy files seamlessly between users.

  • Login to the User from where you would like to copy files from (lets call U1)
  • Run FTP Server using any application of choice like MiXplorer / ES Explorer etc... Note down the details of the port#, username, password etc... and point it to /sdcard
  • Switch user, to where you want to copy files to (lets call U2)
  • Install the FTP browser. If you use MiXplorer / ES Explorer, they will allow you to add a FTP share
  • Use ftp://localhost:2121 assuming the port is 2121, if not change it accordingly and add the FTP share
  • Open the FTP share and you can see all the files & folders of U1 here
  • Copy across to your heart's content !
S.Krishna
  • 868
  • 12
  • 26