Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 6.0 - external storage files being deleted upon app uninstall

My app uses the DownloadManager to download files to a subdirectory of the device's Music folder.

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
...
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/MyStuff/song.mp3");
request.setDestinationUri(Uri.fromFile(file));

I have noticed that the files are being deleted when the app is uninstalled from a device running Marshmallow (this is not happening on older OS versions). Do you have any ideas about this?

Thanks

like image 311
Matteo Innocenti Avatar asked Feb 04 '16 18:02

Matteo Innocenti


People also ask

How do I get rid of leftover files after uninstalling software on Android?

Select “Clear data” and/or “Clear cache.” Depending on the app, there may also be a “Manage data” option to clear additional settings and data. For instance, a browser app may have this option to delete bookmarks and stored passwords.

Does uninstalling an app clear data Android?

Press and hold the app icon. Then, hit "Remove." Next, choose between "Delete App" and "Remove from Home Screen." Deleting an app will erase all its data.

Does uninstalling an app delete save data?

If you uninstall an android app, you lose both the app and it's data as well. Learn why android doesn't store the data and make re-install so difficult.


1 Answers

This is done by an internal class called DownloadReceiver and defined in the com.android.providers.downloads package manifest

<receiver android:name=".DownloadReceiver" android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        <action android:name="android.intent.action.UID_REMOVED" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
        <data android:scheme="file" />
    </intent-filter>
</receiver>

Here the android.intent.action.UID_REMOVED action catches the eye. It was introduced in Lollipop triggering a call to handleUidRemoved() performing

resolver.delete(ALL_DOWNLOADS_CONTENT_URI, Constants.UID + "=" + uid, null);
like image 61
tynn Avatar answered Oct 08 '22 18:10

tynn