保存可由其他应用程序读取和修改的首选项
我构建了一个应用程序,它将使用此处描述的技术从 WebService 下载并安装 APK:
在此安装期间,Web 服务会发送一个“标志”,指示正在更新的应用程序中的 SQLite 数据库是否应在首次运行期间删除。
有没有办法设置一个可以读取的“全局首选项”(如果该标志为 true,则应删除数据库)和清除(删除后应将其设置为 false,以避免在应用程序启动时一直删除数据库) )在第一次使用更新的应用程序时,没有将其保存到 SDCard?
我知道如何从正在更新的应用程序中读取首选项,但是,我没有意识到如何从另一个应用程序修改这些首选项。
多谢。
I built an application that will download and install an APK from a WebService using the technique described here:
Install Application programmatically on Android
During this installation, the Webservice sends a 'flag' that indicates if the SQLite database from the application that is being updated should be deleted or not during it´s first run.
Is there any way to set a "Global Preference" that could be read (if the flag is true, the database should be deleted) and cleared (it should be set to false after deletion to avoid deleting the database all times that app is started) during the first usage of the updated app, without saving it to the SDCard?
I know how to read the preferences from the app that is being updated but, I did´t realize how to modify these preferences from another app.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SharedPreferences 对于每个应用程序/APK 都是唯一的 - 据我所知,无法共享它们,也没有“全局”等效项。
如果您想共享数据,解决方案通常是某种 ContentProvider,但这依赖于两个应用程序同时运行。
如果您只想移交令牌或状态,我建议将文件写入 SDCARD 可能是最简单的选择?
SharedPreferences are unique to each App/APK - no way to share them that I'm aware of and no 'Global' equivalent.
If you want to share data, the solution is usually some sort of ContentProvider, but that relies on both apps running at the same time.
If you only want to hand-over a token or state, I'd suggest writing a file onto the SDCARD is probably the simplest option?
这是教程,介绍如何去做它。
基本上,您必须使用
MODE_WORLD_WRITEABLE
作为首选项文件。要获取其他包的上下文,请使用
createPackageContext()
Here is a tutorial on how to do it.
Basically you have to use
MODE_WORLD_WRITEABLE
for the prefs file.To get the context for the other package you use
createPackageContext()