Two app with shared UserID
You can use android:sharedUserId
in AndroidManifest.xml to let your application share the same user id with another application.
android:sharedUserId
The name of a Linux user ID that will be shared with other
applications. By default, Android assigns each application its own
unique user ID. However, if this attribute is set to the same value
for two or more applications, they will all share the same ID —
provided that they are also signed by the same certificate.
Application with the same user ID can access each other's data and, if
desired, run in the same process.
Notice that they need to be signed by the same certificate.
Two applications share the same user id may access each other's resource.
For example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shareusertesta"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="com.example">
Then we can init a new context of com.example
by:
Context friendContext = this.createPackageContext( "com.example",Context.CONTEXT_IGNORE_SECURITY);
And access some resources of that application:
friendContext.getResources().getString(id);
friendContext.getResources().getDrawable(id);
friendContext.registerReceiver(...);
Two Android applications with the same user ID
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.
How do you make two Android apps share the same user id?
Looks like you can with the sharedUserId manifest attribute. The two apps have to also be signed with the same signature.
How to use one account with multiple apps (AccountAuthenticator, sharedUserId, Google Play App Signing)?
Google Play App signing allows you to re-use the same signature across multiple apps, for precisely this sort of problem.
Just choose "Reuse signing key" when you see this screen:
Two Application's using sharedUserID - createPackageContext issue
First, I really do not recommend this technique. sharedUserId
is mostly for pre-installed apps. In particular, once you publish an app, you can never change the sharedUserId
(including defining one where you did not have one before). If you change sharedUserId
, and the user upgrades from the old sharedUserId
to the new one, your app no longer has access to your app's own files, as they are owned by the old sharedUserId
.
That being said, android:sharedUserId
is an attribute on <manifest>
, not <application>
.
Android Share User ID between two apps
You probably want to learn a bit about android Intents. They one way you could share data between the two apps.
http://developer.android.com/training/sharing/send.html
If all you are passing is a simple bit of text it should be easy.
Another approach is using SharedPreferences, discussed in this Stack thread:
The easiest way to pass data between application in Android
Although the poster seems confident, I am not sure that another app can listen to the SharedPreferences of another app. And if you could it could constitute a serious security risk unless there is some way to assure that ONLY your apps can share that data.
Related Topics
Sethinttextcolor() in Edittext
Check for Access to Notifications Using Notificationlistenerservice
Using Google Places API in Android
How to Get Background Color from Current Theme Programmatically
How to Setup Multiple Alarms in Android
How to Get Pid of Android Application Without Using Adb Shell
Specifying a Link Key in Android Without Pairing
How to Capture Key Events from Bluetooth Headset with Android
Change The Background Color of Cardview Programmatically
Phone Number Validation Android
How to Get The Dimensions of a Drawable in an Imageview
Uninstall App Silently with System Privileges
Firebase Console: How to Specify Click_Action for Notifications
Install_Failed_Cpu_Abi_Incompatible on Device Using Intellij