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 erro开发者_StackOverflow社区r (array cannot be resolved or is not a field) on "array" in "R.array.name_of_arr"
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.
This is impossible to share strings or any other data between two different applications.
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.
精彩评论