15

I have to persist 2 strings for my application even after the application is uninstalled. Regarding that the end users don't have SD cards for their devices and they don't have internet connection, how could I persist those 2 strings even after the app is uninstalled?

I would highly appreciate any response. Thanks

Laura
  • 2,653
  • 7
  • 37
  • 59
  • 1
    Does this answer your question? [How to store data that remains after uninstall](https://stackoverflow.com/questions/4022975/how-to-store-data-that-remains-after-uninstall) – Josh Correia Aug 26 '20 at 21:56

4 Answers4

3

Unless you're targeting VERY old phones, you don't need to worry about not having external storage. As long as you use Environment.getExternalStorageDirectory() as your reference, you shouldn't have a problem, though if you're absolutely concerned about this you can check if the external storage doesn't exist and then opt to go to internal storage. Check out this link from the developer docs for a little more insight.

If External truly isn't available, you could then save to Internal memory, but you will have to declare a new permission for that, which may ward off some people.

Andrew Schuster
  • 3,229
  • 2
  • 21
  • 32
  • I target devices with Android 4.0 and above – Laura Oct 30 '13 at 13:45
  • But if I use the Internal memory all data will be deleted when the app is uninstalled according to android developer site. "By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed." – Laura Oct 30 '13 at 13:47
  • Yes, **By default**. If you give it other contexts, it may persist. If you use other modes such `Context.MODE_APPEND`, `Context.MODE_WORLD_READABLE`, or `Context.MODE_WORLD_WRITABLE` you can potentially get your file to persist after uninstalling. – Andrew Schuster Oct 30 '13 at 13:55
1

You have to write it to an SD card/internal storage, and hope the user does not remove that. However, this is a very fragile approach. There is no other solution, as far as I know.

Jeffrey Klardie
  • 3,020
  • 1
  • 18
  • 23
1

Phones internal storage is also treated as an "SD card". If you create a folder and save it in a text file, it should be safe given user does not manually delete folders after uninstall.

Please check out a section "Saving files that should be shared" in the following web page. Making a file that persists after uninstall entails making it available to other apps/user to read and modify. If those file options aren't intended, you should consider an alternative app design.

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

After re-install, your app can access the created public directory by using the following function:

public static File getExternalStorageDirectory ()

Regarding the function above, per Google:

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

Also, Google recomments placing shared files into a an existing public directory as to not pollute user's root namespace.

C0D3LIC1OU5
  • 8,600
  • 2
  • 37
  • 47
0

Are the strings unique to each user or are they app specific? In either case, the right thing to do would be to save it in some kind of remote server. Firebase is what I use for something like this. Check for its existence in your Application class and download and save it to SQLite if it doesn't exist. For user specific data however, you are going to need some kind of authentication so you know which user is getting what.Firebase does this perfectly well too.

Going by the requirements (no internet, no SD card) of the OP however,I don't see any other way besides one that isn't unethical.

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
  • What Firebase service do you use for this @ojonugwa? I'm well versed with Firebase but can't figure out what service I would use to retain a user's identity. – Anshuul Kai Aug 23 '18 at 20:21