![](/img/trans.png)
[英]Android: Delete app associated files from external storage on Uninstall?
[英]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.