在卸载Android应用程序后保留文件 [英] Keep files after uninstallation of android app

查看:1552
本文介绍了在卸载Android应用程序后保留文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个文件来存储购买的数据。由于该应用程序将是免费的,并在安装时获得一定的积分。
现在发生的是,如果我卸载安装,SD卡上的文件也被删除。所以在重新安装时,你可以再次获得免费的学分。

我使用以下代码:

  File file = new File(mContext.getExternalFilesDir(null),FILENAME); 

尝试{

FileOutputStream os = new FileOutputStream(file);
DataOutputStream out = new DataOutputStream(os);


out.writeInt(5); // 5开始
out.close(); (CreditFileExists()){
Log.w(ExternalStorageFileCreation,First Time so give 5 credits);

if
} else {
Log.e(ExternalStorageFileCreation,创建CreditFile时出错);
Toast.makeText(mContext,R.string.sdnotavailable,Toast.LENGTH_SHORT).show();
}

} catch(IOException e){
//无法创建文件,可能是因为外部存储为
// //当前未挂载。
Log.e(ExternalStorage,Error writing+ file,e);
Toast.makeText(mContext,R.string.sdnotavailable,Toast.LENGTH_SHORT).show();





$ b因此这个文件保存在这个目录下getExternalFilesDir(null),显然那个目录是在卸载时清理的,有人对此有何提示?



谢谢!

解决方案

您可以将文件放在从 Environment.getExternalStorageDirectory()派生的目录中。这些文件将在卸载后保留。但是,无论您的应用程序是否已安装,用户都可以随时删除这些文件。



除此之外,设备上没有地方您可以放置​​在卸载后仍然存在的文件。


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.

这篇关于在卸载Android应用程序后保留文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆