0

I know that it is possible to share SharedPreferences (using the following) when the two apps have the same sharedUserId:

Context secondApp = createPackageContext("com.example.secondapp", 0);
SharedPreferences secondAppPreferences = secondApp.getSharedPreferences("name_of_shared_preferences_file", 0);

but is it at all possible to share strings from the "strings.xml" file so that i can get a string-array from the second app's stings.xml??

i have tried:

secondApp.getResources().getStringArray(R.array.name_of_arr); 

but it throws an error (array cannot be resolved or is not a field) on "array" in "R.array.name_of_arr"

92Jacko
  • 523
  • 2
  • 10
  • 18

3 Answers3

1

It is possible to share "data" (files, preferences, exposed data) between Android applications, but not built in Resources (i.e. the stuff mapped through R). These Resources are all private per application.

Rajiv Makhijani
  • 3,631
  • 32
  • 31
0

I know this question is ten years old, but since the accepted answer is incorrect at this point in time, I'm adding an answer.

If the two apps have the same sharedUserId and signed with the same certificate then it's possible to

fun Context?.getSettingsContext() = this?.createPackageContext("com.android.settings", Context.CONTEXT_RESTRICTED)

to get the context (from in this case native settings), and then

with(settingsContext.resources) {
        val resId = getIdentifier("accessibility_screen_magnification_gestures_title", "string", "com.android.settings")
        Log.d(TAG, "titleId: ${getString(resId)}")
}

also mentioned in this response.

jayeffkay
  • 1,229
  • 1
  • 16
  • 22
0

This is impossible to share strings or any other data between two different applications.

Eugene
  • 59,186
  • 91
  • 226
  • 333
  • Any other data? but it is possible to share files, preferences, and i think, databases between applications with the same android:sharedUserId – 92Jacko Aug 27 '11 at 15:15