92Jacko
92Jacko

Reputation: 523

possible to share strings.xml between apps with the same sharedUserId?

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"

Upvotes: 0

Views: 349

Answers (3)

jayeffkay
jayeffkay

Reputation: 1299

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.

Upvotes: 0

Rajiv Makhijani
Rajiv Makhijani

Reputation: 3651

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.

Upvotes: 1

Eugene
Eugene

Reputation: 60184

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

Upvotes: 0

Related Questions