I want to use a file to store purchased data. Since the app is going to be free and a certain amount of credits are given at the installation. What happens now is that if I uninstall the installation, also the files on the SD card are deleted. So at reinstallation you have your free credits again.
I use 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 saved in this directory getExternalFilesDir(null), apparently that directory is cleaned at uninstallation, anybody any tips for this matter?
Thanks!
You can put files in a directory derived from Environment.getExternalStorageDirectory()
. These files will persist after an uninstall. However, a user can delete those files any time they like, regardless of whether your app is installed or not.
Other than that, there is no place on the device that you can place files that will survive an uninstall.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With