可以在具有相同sharedUserId的应用程序之间共享strings.xml吗?
我知道当两个应用程序具有相同的sharedUserId时,可以共享SharedPreferences(使用以下内容):
Context secondApp = createPackageContext("com.example.secondapp", 0);
SharedPreferences secondAppPreferences = secondApp.getSharedPreferences("name_of_shared_preferences_file", 0);
但是是否可以共享“strings.xml”文件中的字符串,以便我可以从中获取字符串数组第二个应用程序的stings.xml?
我已经尝试过:
secondApp.getResources().getStringArray(R.array.name_of_arr);
但它在“R.array.name_of_arr”中的“array”上抛出错误(数组无法解析或不是字段)
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以在 Android 应用程序之间共享“数据”(文件、首选项、公开数据),但不能内置资源(即通过 R 映射的内容)。这些资源对于每个应用程序都是私有的。
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.
我知道这个问题已经有十年了,但由于此时接受的答案不正确,所以我添加了一个答案。
如果两个应用程序具有相同的
sharedUserId
并使用相同的证书签名,则可以获取上下文(在本例中为本机设置),然后
也在 此响应。
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 toto get the context (from in this case native settings), and then
also mentioned in this response.