Sharing files/ installation directory between two apps
Asked Answered
A

2

2

I have two apps on Android which need to share few files among them. Right now I share files via a ftp server.

Is there a way I can authenticate these apps to each other so that they can look into each others installed directory?

Thank you. AAT

Asmara answered 21/9, 2012 at 12:51 Comment(0)
A
2

You need to set android:sharedUserId in manifest for both apps and sign them with the same certificate:

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.

Adytum answered 21/9, 2012 at 13:29 Comment(1)
This constant was deprecated in API level 29.Ma
C
-1

Version1 (com.example.v1):

Call you SharedPrefences with the following flags:

getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE | MODE_MULTI_PROCESS);

Free version (com.example.v2):

try {
     mContext = createPackageContext("com.example.game.v2", 0);
     mSharedPrefs = mContext.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE | MODE_MULTI_PROCESS);
} catch (NameNotFoundException e) {
     e.printStackTrace();
}

This works both ways and you can share your preferences among your applications

Caliph answered 21/9, 2012 at 12:59 Comment(2)
I am not sure how this will help. Sharing preference file / files is quite different than sharing files.Seftton
Using MODE_WORLD_READABLE flag will allow all applications to read prefs, not sharing only between 2 apps.Adytum

© 2022 - 2024 — McMap. All rights reserved.