Android - Preserve or delete files created by the application on uninstall

后端 未结 6 1916
别跟我提以往
别跟我提以往 2020-11-29 05:52

I created an application which creates and stores files to sdcard. Is there a way to bind the folder with application in order to delete all files when the user runs uninsta

6条回答
  •  遥遥无期
    2020-11-29 06:19

    Seems like there have been some developments since 2009 :).

    From the documentation:

    If you're using API Level 8 or greater, use getExternalCacheDir() to open a File that represents the external storage directory where you should save cache files. If the user uninstalls your application, these files will be automatically deleted. However, during the life of your application, you should manage these cache files and remove those that aren't needed in order to preserve file space.

    If you're using API Level 7 or lower, use getExternalStorageDirectory() to open a File that represents the root of the external storage, then write your cache data in the following directory:

    /Android/data//cache/ The is your Java-style package name, such as "com.example.android.app".

提交回复
热议问题