简体   繁体   中英

Saving preference that can be read and modified by another Application

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.

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM