Store files after uninstalling Android application

I want to use a file to store the acquired data. Since the application will be free, and a certain amount of credits will be provided on the installation. What is happening now is that if I remove the installation, the files on the SD card are also deleted. Therefore, when reinstalling, you again have your free credits.

I am using the following code:

File file = new File(mContext.getExternalFilesDir(null), FILENAME); try { FileOutputStream os = new FileOutputStream(file); DataOutputStream out = new DataOutputStream(os); out.writeInt(5); //5 CREDITS TO START out.close(); if(CreditFileExists()) { Log.w("ExternalStorageFileCreation", "First Time so give 5 credits"); } else { Log.e("ExternalStorageFileCreation", "Error in creating CreditFile"); Toast.makeText(mContext, R.string.sdnotavailable, Toast.LENGTH_SHORT).show(); } } catch (IOException e) { // Unable to create file, likely because external storage is // not currently mounted. Log.e("ExternalStorage", "Error writing " + file, e); Toast.makeText(mContext, R.string.sdnotavailable, Toast.LENGTH_SHORT).show(); } 

So, the file is stored in this directory getExternalFilesDir (null), apparently this directory is cleared when it is deleted, does anyone have any tips on this?

Thanks!

+4
source share
1 answer

You can put the files in the directory obtained from Environment.getExternalStorageDirectory() . After deletion, these files are saved. However, the user can delete these files at any time convenient for them, regardless of whether your application is installed or not.

In addition, there is no space on the device to place files that can withstand deletion.

+7
source

Source: https://habr.com/ru/post/1257357/


All Articles