Delete app created folder on app uninstall



Is there a way to register when a user tries to uninstall a nativescript app, display a pop up message and run some code ?
My app creates a folder in users’ external storage and I want to ask them if they want to delete the folder when they uninstall. Or at least simply delete that on uninstall ?


Sadly, there is no way you can detect your own app’s uninstallation even in native android.


It depends a little on what ‘external storage’ means. If it’s simply the type of (public) storage that allows other apps to access your app’s files, then those files will be deleted when your app is uninstalled.

This SO topic explains it better:, but it boils down to the question: which method do you use to determine the external files folder?


I use this method to access external files folder : android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS)
I then create a folder inside it and let the user download files in it.

Looking at the topic you’ve linked, I should try to change the directory to /Android/data/APP_PACKAGE_NAME/ and it seems there is no way to register uninstall event sadly.

Thanks for the help


The SO topic does not give correct informations about how to get the directory Android/data …
I found a way that works :

let androidDownloadsPath = android.os.Environment.getExternalStorageDirectory().toString();
let customFolderPath = fs.path.join(androidDownloadsPath,'Android/data/APP_PACKAGE_NAME');

I can confirm files in this folder get deleted when the app is uninstalled :+1: