72

I am confused in sharedUserID.what is use of sharedUserId?How to use?Where to use in android?

Phillip
  • 5,366
  • 10
  • 43
  • 62
Bhargav Panchal
  • 1,159
  • 1
  • 12
  • 27
  • 2
    `sharedUserID` flag is deprecated in `API level 29` https://developer.android.com/guide/topics/manifest/manifest-element#uid – mstrengis Mar 09 '20 at 09:26

2 Answers2

44

By default, Android assigns a user id to an application. It is the unique id for your application and means that nobody except the user with this id can reach your application's resources. You cannot access the data of an other application or run it in your current process. when, from an activity, an activity of another application is called android passes the control to the new activity called and they run in totally different processes.

However, in your manifest file, you can explicitly identify a user id for your application. When you declare the same user id for more than one application, they can reach each other's resources (data fields, views, etc.). You can display data from another application or run it in your process.

this is how you use it: from http://developer.android.com/guide/topics/manifest/manifest-element.html

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="string"
    android:sharedUserId="string"
    android:sharedUserLabel="string resource" 
    android:versionCode="integer"
    android:versionName="string"
    android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
    . . .</manifest>
cagla
  • 538
  • 4
  • 7
  • 49
    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. – njzk2 Mar 20 '12 at 09:25
  • 1
    How many applications can have same sharedUserId in a device? If I am having five applications with same userId in a device will it affect the applications performance as they are running in same process ? – Piyush Agarwal Jul 08 '13 at 20:30
  • 1
    @pyus13 I don't believe they are forced to run in the same process. That is just an option if you desire to do so. – Lo-Tan Apr 16 '14 at 02:27
  • 1
    I have shared user id in many of my apps to share private preferences. The surprising thing is they works fine if I have targetSDK version 9 but if i have targetSK version 14 it stopped working. – Piyush Agarwal Apr 16 '14 at 07:15
  • 4
    Works fine for me (target API 21) with at least 3 apps sharing the same UserId. – Hartok Jan 13 '15 at 15:55
  • Note that sharedUserId is deprecated so you should use other alternatives instead: https://developer.android.com/guide/topics/manifest/manifest-element#uid – android developer Aug 23 '23 at 07:04
39

SharedUserId is used to share the data,processes etc between two or more applications. It is defined in AndroidManifest.xml like,

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="android.uid.shared"
    android:sharedUserLabel="@string/sharedUserLabel"
    ...>

and define the shared parameter in Android.mk for that app, like

LOCAL_CERTIFICATE := shared

Hope its helpful to you.

SapuSeven
  • 1,473
  • 17
  • 30
Parthraj
  • 573
  • 5
  • 16
  • 3
    How do you modify Android.mk? I haven't seen any references to it informing us on what that file is all about... – IgorGanapolsky Jan 01 '14 at 23:44
  • 4
    @IgorGanapolsky Android.mk is a makefile for Android NDK (C/C++). If your app uses Java only, you don't have one. – Hartok Jan 13 '15 at 15:06
  • 4
    That is incorrect. This file is required for ALL applications which are to be built as part of AOSP. Including java only ones. – RocketRandom Jun 15 '16 at 10:21
  • 1
    No its not necessary to set the mk file – The Dude Jun 20 '17 at 12:50
  • From Android documentation, "Shared user IDs cause non-deterministic behavior within the package manager. As such, its use is strongly discouraged and may be removed in a future version of Android. Instead, apps should use proper communication mechanisms, such as services and content providers, to facilitate interoperability between shared components." – Prudhvi Dec 23 '19 at 18:29