我想使用文件来存储购买的数据。由于该应用将免费,并在安装时获得一定的积分。 现在发生的情况是,如果我卸载安装,SD卡上的文件也会被删除。因此,在重新安装时,您可以再次获得免费积分。卸载安卓应用程序后保留文件
我使用下面的代码:
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();
}
所以文件保存在这个目录getExternalFilesDir(空),显然这个目录是在卸载干净,任何人对此事的任何提示?
谢谢!
嗯......我用了或多或少相同的代码,并且遇到了文件BEING KEPT而不是被删除的问题...... – Eugen 2012-03-15 19:44:42