简体   繁体   English

Android 6.0 - 卸载应用时删除外部存储文件

[英]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将文件下载到设备的Music文件夹的子目录中。

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). 我注意到当从运行Marshmallow的设备上卸载应用程序时,文件正在被删除(这在旧版操作系统版本中不会发生)。 Do you have any ideas about this? 你有什么想法吗?

Thanks 谢谢

This is done by an internal class called DownloadReceiver and defined in the com.android.providers.downloads package manifest 这是由一个名为DownloadReceiver的内部类完成的,并在com.android.providers.downloads 包清单中定义。

<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. 这里android.intent.action.UID_REMOVED动作引人注目。 It was introduced in Lollipop triggering a call to handleUidRemoved() performing 它是在Lollipop中引入的,触发对handleUidRemoved()执行的调用

resolver.delete(ALL_DOWNLOADS_CONTENT_URI, Constants.UID + "=" + uid, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:在卸载时从外部存储中删除应用相关文件? - Android: Delete app associated files from external storage on Uninstall? 在卸载Android 2.3时擦除应用程序外部文件 - Erase app external files on uninstall Android 2.3 卸载应用程序时,不会删除内部存储“getFilesDir()”中的文件 - Files in internal storage "getFilesDir()" are not being deleted when app is uninstalled 在 android 6.0 中获取外部存储路径? - Get external storage path in android 6.0? Android,如何防止卸载应用程序时删除内部存储文件 - Android, how to prevent internal storage files to be deleted when the app is uninstalled 更新应用程序时会删除外部存储文件夹吗? - Will external Storage Folder be deleted when App is updated? 卸载后清除内部存储 - Clearing Internal Storage Upon Uninstall Android 应用程序无法读取外部存储文件 - Android app can't read external storage files 卸载时如何删除Android外部存储公共目录中的图片? - How to delete pictures in Android External Storage Public Directory at uninstall? FileObserver不适用于Android 6.0 Marshmallow(API 23)中的外部存储 - FileObserver does not work on external storage in Android 6.0 Marshmallow (API 23)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM