When I delete my application, will I delete my folder created through my application?

I ran into this problem that when I delete my application folder still accessible in the sdcard path,

What to do to remove it?

suggest something to make this happen ...

+4
source share
4 answers

What to do to remove it?

Use getExternalFilesDir() and / or getExternalCacheDir() for your files on external storage ("sdcard"). These directories are automatically deleted when your application is deleted.

Other than this, nothing else is possible, since you do not get control when your application is deleted.

+11
source

Unfortunately, in simple words the answer is no, you cannot.

Causes:

  • You need to broadcast what you can listen to when the application is disconnected. but the application that will be deleted will not receive any broadcast to remove it.

  • If you have created any folders on the external storage of the device, you will not be able to call the code when the user uninstalls your application.

Suggestions and solutions:

  • The only way to do this. If you use getExternalCacheDir() , then when you delete the application, only folders are automatically deleted.

  • If you are targeting API level 8 or higher, you can use Context#getExternalFilesDir() for your external files and they will be deleted when deleted.

+7
source

Some indications: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

If you use API level 8 or higher, use getExternalFilesDir () to open a file representing the external memory directory in which you should save your files. This method takes a type parameter that indicates the type of subdirectory you want, for example DIRECTORY_MUSIC and DIRECTORY_RINGTONES (pass null to get the root of the directory of your application file). If necessary, this method will create the appropriate directory. (...)

If you are using API level 7 or lower, use getExternalStorageDirectory () to open a file representing the root of the external storage. Then you should write your data in the following directory:

/ Android / data / "package_name" / files /

package_name is your Java-style package name, for example, com.example.android.app.

If the user device works with API level 8 or higher and they delete your application, this directory and all its contents will be deleted.

+2
source

You cannot run the code when your application is uninstalled, so you must allow the OS to clean up for you. This means that you cannot place files anywhere on the SD card, but must follow the rules of the OS.

Instead of creating your own directory structure on an SD card, you should place the files you write in the directories returned by getExternalFilesDir() and getExternalCacheDir() . Android then automatically deletes any contents of these directories when it deletes.

0
source

All Articles