问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/12530972/sharing-files-installation-directory-between-two-apps