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

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

问题描述

我想使用一个文件来存储购买的数据.由于该应用程序将是免费的,并且在安装时会提供一定数量的积分.现在发生的是,如果我卸载安装,SD 卡上的文件也会被删除.因此,在重新安装时,您将再次获得免费积分.

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.

我使用以下代码:

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(null),显然该目录是在卸载时清理的,有人对此有什么提示吗?

So the file is saved in this directory getExternalFilesDir(null), apparently that directory is cleaned at uninstallation, anybody any tips for this matter?

谢谢!

推荐答案

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

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天全站免登陆