Android: Delete app associated files from external storage on Uninstall?

后端 未结 4 925
情话喂你
情话喂你 2021-01-02 08:15

It\'d be convenient if an application I\'m writing stored some files to external storage permanently (so they persist after the application has been exited[destroyed]), but

相关标签:
4条回答
  • 2021-01-02 08:37

    Yes, this is possible. Simply write your files to the external files directory:

    File dir = getExternalFilesDir(null);
    

    This will create a folder at /Android/data/your.package/. Note that this is not External as in sdcard, but it is publicly accessible. If a user uninstalls your app, this directory will also be removed, along with all of its contents.

    0 讨论(0)
  • 2021-01-02 08:39

    actually it is possible .

    android will automatically remove files of the app in the external storage , but the files must be inside a specific path of the app :

    "...../Android/data/APP_PACKAGE_NAME/"

    where APP_PACKAGE_NAME is the application's package name. another path that is automatically being emptied is :

    "...../Android/obb/APP_PACKAGE_NAME/" where APP_PACKAGE_NAME is the application's package name.

    the data is for anything you wish. the obb folder is for huge files that are downloaded using the play-store and the apk extension library . you are not supposed to create files there .

    0 讨论(0)
  • 2021-01-02 08:42

    No, I don't believe so. Only files that you write to internal storage will be removed when your application is uninstalled (or if the user presses the 'clear data' button in the Application settings app).

    Your app can't receive its own PACKAGE_REMOVED broadcast intent either, so you essentially have no notification that you're being uninstalled.

    0 讨论(0)
  • 2021-01-02 08:49

    Quoting from the blog post of CommonsWare

    • Internal storage: your file is deleted

    • External storage: if you wrote your file to a location rooted at getExternalFilesDir() or getExternalCacheDir(), your file is deleted. If you wrote your file elsewhere (e.g., Environment.getExternalStoragePublicDirectory()), your file is not deleted

    • Removable storage, prior to Android 4.4: removable storage is not officially accessible; if your file winds up out there, it should not be deleted when your app is uninstalled

    • Removable storage, Android 4.4+: AFAIK, if you write to a supported location (getExternalFilesDirs() or getExternalCacheDirs()), your file is deleted if that particular bit of removable storage is in the device at the time of uninstall

    0 讨论(0)
提交回复
热议问题