繁体   English   中英

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

[英]Android 6.0 - external storage files being deleted upon app uninstall

我的应用程序使用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));

我注意到当从运行Marshmallow的设备上卸载应用程序时,文件正在被删除(这在旧版操作系统版本中不会发生)。 你有什么想法吗?

谢谢

这是由一个名为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>

这里android.intent.action.UID_REMOVED动作引人注目。 它是在Lollipop中引入的,触发对handleUidRemoved()执行的调用

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM