[英]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.