0

I have an app that downloads a zip file from a server and unzips them into the device's photo directory or something (I can't remember at the moment), only problem is those files will still exist when the app is deleted (as expected). Is there a folder that comes with an app in which I can store my downloaded files into and will be deleted if the app is uninstalled?

4 Answers4

0

Save files in the your app directory, you can use

public static void WriteFile(Context context, String fileName, String data) {
    try {
        FileOutputStream fileOut = context.openFileOutput(fileName, MODE_PRIVATE);
        OutputStreamWriter outputWriter = new OutputStreamWriter(fileOut);
        outputWriter.write(data);
        outputWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Hamza rasaee
  • 362
  • 4
  • 12
0

Try to save your file only accessible to your app not to other app then when your app would be unistalled along with that app data will deleted automatically. See link below for more information as some lines are avail here for your concern. https://developer.android.com/training/camera/photobasics.html

amit kumar
  • 42
  • 4
0

You can store files related to your app by using an OutputStream. Those files can be access from within your code (using an InputStream) and will be deleted after deinstallation of the app.

The Streams write and read bytes, so you need to convert whatever you want to store to bytes.

Assuming you want to store images, you should have a look at this example.

RawkFist
  • 474
  • 5
  • 12
0

Refer to this, select the Saving Files, you can see there are two ways to store files in Android devices:

Internal Storage

External Storage

  • Have permission.
  • When the user uninstalls your app, the system removes your app's files from here only if you save them in the directory from getExternalFilesDir().
  • This is about ExternalStorageDirectory.
Community
  • 1
  • 1
Robbit
  • 4,300
  • 1
  • 13
  • 29