2

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.

Community
  • 1
  • 1
regisxp
  • 956
  • 2
  • 10
  • 31

2 Answers2

1

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?

0

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

Reno
  • 33,594
  • 11
  • 89
  • 102
  • Hi @Reno The example only shows how to read the configurations saved by anoter app. On my app (that will be updated), I did the following to create the config file: `code` SharedPreferences stng = getSharedPreferences("AppPrefs", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); SharedPreferences.Editor edt = stng.edit(); edt.putBoolean("DeleteDatabase", false); edt.commit(); //Return True `code` On the Updater App, the code is almost same, except by the context that is get by createPackageContext("Package.Name", 0); The call to editor.commit() always returns false. Any advice? – regisxp Oct 27 '11 at 13:24