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!
Diego source share