19

From http://developer.android.com/guide/topics/fundamentals.html:

It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).

How can we achieve same user ID for two applications? Any example?

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
SBK
  • 1,585
  • 2
  • 16
  • 19

1 Answers1

29

You can do this by setting the sharedUserId and sharedUserLabel in the AndroidManifest.xml file to the same value. As an example, if I have the following 2 manifest files (I only included the beginning):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.package1" 
      android:sharedUserId="userId"
      android:sharedUserLabel="@string/label_shared_user" 
      android:versionCode="1" 
      android:versionName="1.0.0">

and

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.package2" 
      android:sharedUserId="userId"
      android:sharedUserLabel="@string/label_shared_user" 
      android:versionCode="1" 
      android:versionName="1.0.0">

then they will both share the same user.

Hrishikesh Kadam
  • 35,376
  • 3
  • 26
  • 36
Femi
  • 64,273
  • 8
  • 118
  • 148
  • 7
    However I strongly discourage doing this. The vast majority of apps shouldn't do it; it is only for special cases. Using this results in a lot of subtle differences in behavior (such as all of the apps sharing the same permissions) that most developers shouldn't be inflicting upon themselves. – hackbod Jun 15 '11 at 07:50
  • That is great !!! but also is there a way to get applications having same shareUserId from a third application. I mean i wish to detect the 2 applications having same sharedUserId – AbhishekB Oct 30 '12 at 14:49
  • Look at http://developer.android.com/reference/android/content/pm/ApplicationInfo.html: the uid will be the same for both applications. – Femi Oct 30 '12 at 18:26
  • 3
    an important addition is that you can only install two applications with the same shareduserid is both the applications were signed with the same certificate – Zar E Ahmer Jan 26 '15 at 11:00
  • @hackbod *"it is only for special cases"* Can you give some examples? – Mehdi Charife Feb 11 '23 at 10:28